问题
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