开发者

Difference between these two logical flows and need help in correcting it

开发者 https://www.devze.com 2023-03-21 04:47 出处:网络
var array = [\'single\', \'multiple\'] for (vb = 0, len = obj.length; vb < len; vb++) { var row = Ti.UI.createTableViewRow({
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) {
0

精彩评论

暂无评论...
验证码 换一张
取 消