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

隐身守侯 提交于 2019-12-25 09:28:52

问题


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


回答1:


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);
    }
});


来源:https://stackoverflow.com/questions/26374903/how-to-bind-the-data-in-to-label-in-titanium-alloy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!