0

我有repeater.js,m在其中获取加载值。这是setupItem方法..

我想在单击按钮时获得相同的值..如果列表和中继器都出现此问题...数据正在加载 onload 但在按钮上它不起作用...任何人都可以帮助...

enyo.kind({
    name: "enyo.sample.RepeaterSample",
    classes: "enyo-fit repeater-sample",
    components: [
        {kind: "Repeater", onSetupItem:"setupItem", components: [
            {name:"item", classes:"repeater-sample-item", components: [
                {tag:"span", name: "personNumber"},
                {tag:"span", name: "personName"}
            ]}
        ]},
        //{kind: "onyx.Button", content:"Fetch", ontap:"setupItem"}
    ],
    create: function() {
        this.inherited(arguments);
        this.$.repeater.setCount(this.people.length);
        this.peopleChanged();
    },
    published: {
        people: []
    },
    peopleChanged: function() {
        for(var i=0;i < 5;i++){
            this.people[i]="art "+i;
        }
        this.$.repeater.setCount(this.people.length);
    },
    setupItem: function(inSender, inEvent) {
        var index = inEvent.index;
        var item = inEvent.item;
        alert(this.people[index]);
        var person = this.people[index];
        //item.$.personNumber.setContent((index) + ". ");
        item.$.personName.setContent(person);
        //item.$.personName.applyStyle("color", person.sex == "male" ? "dodgerblue" :        "deeppink");
    },
});
4

1 回答 1

0

我认为您可能会混淆这里需要发生的事情。setupItem 方法应该只被调用以响应当您对其进行 .setCount() 或 .build() 时列表抛出的 onSetupItem 事件。

因此,按钮 ontap 的处理程序应设置数组的内容,然后更改列表上的计数(使用 setCount())或直接调用 .build()。

于 2012-09-07T14:59:41.167 回答