javascript-Telerik Nativescript移动应用程序中的基本模糊事件
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript-Telerik Nativescript移动应用程序中的基本模糊事件,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2583字,纯文字阅读大概需要4分钟。
内容图文
![javascript-Telerik Nativescript移动应用程序中的基本模糊事件](/upload/InfoBanner/zyjiaocheng/691/2d0f5656e07f49f59dac523b518c77c9.jpg)
我正在使用带有NativeScript的Telerik AppBuilder编写跨平台的移动应用程序.我正在努力弄清楚如何在TextField上获取基本的“模糊”或“ onTextChanged”事件.我可以弄清楚如何执行“轻击”事件之类的事情,但是为什么很难找到某人进行“模糊”或“ onTextChanged”的样本呢?
我已经试过了:
var tagField = view.getViewById(page, "tfDescription")
tagField.set("onblur", function(eventData) {
pageData.set("debug", "blur this field: " + JSON.stringify(eventData));
});
我还尝试了xml中可以想到的每个属性:
<TextField id="tfDescription" blur="blur" onblur="blur" onLoseFocus="blur" focusLost="blur" textChanged="blur" row="2" text="{{ description }}" />
这些都不起作用.有人知道如何执行此操作吗?
谢谢
解决方法:
据我所知,NativeScript中没有模糊(类似)事件.但是,您可以对更改文本时做出反应.
您要做的是利用Data Binding Mechanisms和
NativeScript中的Observable Object.
简要地说,数据绑定将使您能够将用户界面(最经常在XML文件中描述)与业务模型/数据对象连接.数据绑定可以是“单向”的,这意味着您对数据对象所做的任何更改都将反映在UI中.也可以有两种方式,这意味着您在UI中所做的任何更改也将反映在您的数据对象中.
对于您的情况,您希望双向绑定,因为您希望UI(用户输入文本)中发生的任何事情都反映在模型中.
例
XML
假设您有以下xml:
<Page xmlns="http://www.nativescript.org/tns.xsd" loaded="pageLoaded">
<StackLayout>
<TextField text="{{ description }}" />
</StackLayout>
</Page>
JS
我已在内联评论以方便理解.
var observable = require("data/observable");
function pageLoaded(args) {
var page = args.object;
/**
* Creating a new Observable object.
*/
var contextObj = new observable.Observable();
/**
* Setting the property 'description' to 'hi there'.
* In your XML you'll attach this property to the
* Text field as such:
* <TextField text="{{ description }}" />
* This means that the Text field will, by default
* be prepopulated with 'Hi there'
*/
contextObj.set("description", "Hi there");
/**
* Attaching the observable object to the
* 'bindingContext' of the page. This is a
* special property to which you want to attach
* the object. By default bindings are two way.
*/
page.bindingContext = contextObj;
/**
* Event listener.
* When the user is changing the text in the UI, this gets propagated down
* to the contextObj which will change. Here we add an event listener for
* changes and log some information about the change that just happened.
*/
contextObj.addEventListener(observable.Observable.propertyChangeEvent, function (event) {
console.log('The object changed!');
console.log('Event: ' + event.eventName);
console.log('propertyName: ' + event.propertyName);
console.log('New value: ' + event.value);
console.log('');
});
}
exports.pageLoaded = pageLoaded;
内容总结
以上是互联网集市为您收集整理的javascript-Telerik Nativescript移动应用程序中的基本模糊事件全部内容,希望文章能够帮你解决javascript-Telerik Nativescript移动应用程序中的基本模糊事件所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。