简体   繁体   中英

How to bind the data in to label in Titanium alloy?

How can I bind data from controller to xml, My code is as follows,

View:

  <Collection src="respondentAge"/>
    <Label id="question"></Label>

Styles

".question":{
    font:{
        fontSize:18,
        fontWeight:'normal'
    },
    color:"#000",
    left:10,
    height:Ti.UI.SIZE
}

Controller

     var agenames = Alloy.Collections.respondentAge;
     agenames.on("reset", function() {
       var agenamesLength = agenames.length;
       var question; 
       for (var i = 0; i < agenamesLength; i++) {
            question = agenames.at(i).get("quesion");
         // I need to bind the 'agenames.at(i).get("quesion")' value in to label in 
       }
      });
   agenames.fetch({
       query:"SELECT * FROM respondentAge WHERE languageID ='1';"
  });

The question text is coming from the database, So for for question I have added the label and I'm retrieving the value from database and I need to set the label value as retrieving value.

How can I do that

I propose you use the setText(text) property of Label. You can read more about it here: Label docs

agenames.on("reset", function() {
    var agenamesLength = agenames.length;
    var question; 
    for (var i = 0; i < agenamesLength; i++) {
        question = agenames.at(i).get("quesion");
        $.question.setText(question);
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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