按钮方法的onclick不在enyo.js中工作,但工作正常上载列表或转发器

时间:2012-09-07 11:04:45

标签: javascript enyo

我有repeater.js,其中m得到load.that是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");
    },
});

1 个答案:

答案 0 :(得分:0)

我认为你可能会混淆这里需要发生的事情。只应调用setupItem方法以响应当你对它设置.setCount()或.build()时由列表抛出的onSetupItem事件。

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