Onclick of button method not working in enyo.js but working fine onload of list or repeater

StackOverflow https://stackoverflow.com/questions/12316852

  •  30-06-2021
  •  | 
  •  

Question

I have the the repeater.js in which m getting the values on load.that is setupItem method..

I want to get the same value on click of an button..This problem m getting in case of both list and repeater...data are loading onload but on button its not working...can anyone help....

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");
    },
});
Was it helpful?

Solution

I think you may be confusing what needs to happen here. The setupItem method should only be called in response to the onSetupItem event that is thrown by the list when you .setCount() on it or .build() it.

So, the handler for ontap of your button should set the contents of the array, then either change the count on the list (with setCount()) or call .build() on it directly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top