ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

javascript-Telerik Nativescript移动应用程序中的基本模糊事件

2019-10-12 20:36:25  阅读:223  来源: 互联网

标签:nativescript javascript mobile telerik


我正在使用带有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;

标签:nativescript,javascript,mobile,telerik
来源: https://codeday.me/bug/20191012/1902877.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有