简体   繁体   English

中继器本机脚本中的TextChange

[英]TextChange in repeater nativescript

i trying do to textchange in repeater and research this link. 我试图在转发器中进行textchange并研究此链接。

Basic blur event in a Telerik Nativescript Mobile App Telerik Nativescript移动应用程序中的基本模糊事件

It work in single textfield but no work in repeater. 它只能在单个文本字段中工作,而不能在中继器中工作。 Isn't set wrong anything? 没错吗?

XML: XML:

 <Repeater id="lstSelectedItemsSingle" items="{{itemsSingle}}">
                    <Repeater.itemTemplate>
                        <GridLayout columns="auto,*,auto,*,auto" rows="auto,auto,1" padding="6" id = "{{ matchId + dataType + 'GridSingle'}}">
                            <GridLayout columns="*,*,*" rows="40" col="3" borderRadius="6" borderWidth="1" borderColor="#DBDBDB" >
                                <button backgroundImage="res://reduce_enable" style="background-repeat:no-repeat;background-position: 50% 50%"  backgroundColor="#BFBFBF" />
                                <TextField col="1" backgroundColor="#ffffff" col="1" text="{{stake}}" style="text-align:center" keyboardType="number"  /> 
                                <button backgroundImage="res://add_icon_enable" col="2" style="background-repeat:no-repeat;background-position: 50% 50%" backgroundColor="#BFBFBF"  col="2"/>
                            </GridLayout> 
                        </GridLayout>
                    </Repeater.itemTemplate>   
                </Repeater>

Model: 模型:

exports.onPageLoaded = function(args){
    page = args.object;

    viewM.set("stake", "2");

    viewM.addEventListener(observable.Observable.propertyChangeEvent, function (event) { 
        console.log(event.propertyName); 
        }
    });
}

It's probably because repeaters are bound to a list of items - usually observables. 这可能是因为转发器绑定到了一个项目列表-通常是可观察到的。 If you bind inside the repeater using "{{ }}", NativeScript is going to look for that method on that specific object in the repeater. 如果使用“ {{}}”绑定到转发器内部,则NativeScript将在转发器中的特定对象上查找该方法。 So your code should be structured something like this (TypeScript) ... 因此,您的代码应采用类似这样的结构(TypeScript)...

import { Observable, EventData } from 'data/observable';
import { Page } from 'ui/page';

class Item extends Observable({
    text: string = '';
    constructor(text: string) {

        this.text = text;

        this.todos.on(ObservableArray.changeEvent, (args: any) => {
            // handle text change
        });
    }
});

class ViewModel extends Observable({
    items: ObservableArray<Items>

    constructor() {
        this.items = new ObservableArray<Items>({
            new Item('Thing 1'),
            new Item('Thing 2')
        });
    }
});

let loaded = (args: EventData) => {
    let page = <Page>args.object;
    page.bindingContext = new ViewModel();   
}

export { loaded }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM