转发器nativescript中的TextChange

时间:2016-02-15 10:42:54

标签: nativescript

我尝试在转发器中进行文本转换并研究此链接。

Basic blur event in a Telerik Nativescript Mobile App

它在单个文本字段中工作,但在转发器中没有工作。是不是错了什么?

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>

型号:

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

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

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

1 个答案:

答案 0 :(得分:0)

这可能是因为转发器被绑定到一个项目列表 - 通常是可观察的。如果使用“{{}}”绑定到转发器内部,NativeScript将在转发器中的特定对象上查找该方法。所以你的代码应该像这样结构化(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 }