var array = ['single', 'multiple']
for (vb = 0, len = obj.length; vb < len; vb++) {
var row = Ti.UI.createTableViewRow({
height: 35,
selectionStyle: 'NONE'
});
row.add(Ti.UI.createLabel(pm.combine($$.labelBrown, {
left: 10,
text: obj[vb]
})));
row.add(Ti.UI.createLabel(p开发者_Go百科m.combine($$.labelBrown, {
left: 220,
text: 'Information to be displayed'
})));
this.rowData[vb] = row;
}
// The above code works fine and does print the dynamic rows.
The below code does not work... why?
var obj= { single: ["one", "sd"], multiple: ["two", "sdsd"] },
for (vb in obj) {
if (obj.hasOwnProperty(vb)) {
for (var i = 0, len = vb.length; i < len; ++i) {
var row = Ti.UI.createTableViewRow({
height: 35,
selectionStyle: 'NONE'
});
row.add(Ti.UI.createLabel(pm.combine($$.labelBrown, {
left: 10,
text: vb
})));
row.add(Ti.UI.createLabel(pm.combine($$.labelBrown, {
left: 220,
text: obj[vb][0]
})));
this.rowData[vb] = row;
}
}
}
I am trying to create a rows dynamically based on the Array. I changed to Obj, to have key and value properties inside it... it does not work...
Use a semi colon at the end:
var obj= { single: ["one", "sd"], multiple: ["two", "sdsd"] };
Declare vb
locally:
for (var vb in obj) {
And
for (var i = 0, len = vb.length; i < len; ++i) {
should be
for (var i = 0, len = obj[vb].length; i < len; ++i) {
精彩评论