0

全部

我现在正在使用 WebOs 3.0 这个问题可能不需要 WebOs 知识。

我的问题是我使用的列表选择器就像一个 HTML 下拉列表。

它的静态代码

{kind: "ListSelector", name: "mySelector"}

this.$.mySelector.setItems( [ { caption: "test 1", value: 1 }, { caption: "test 2", value: 2 } ]);
this.$.mySelector.setValue(2);

动态显示方式

for (var j=0; j<this.cnt; j++)
      {
      //alert(this.data[j].channelName);
      this.$.mySelector.setItems( [ { caption: this.data[j].channelName, value: this.data[j].channelId }]);

      }

因为我一直在用“setItems”替换你所有的项目。它只显示我的数据库的最后一个值。

4

1 回答 1

2

为什么不改变循环来建立一个临时数组,然后调用 setItems 函数呢?

var items = [];
for (var j=0; j<this.cnt; j++)
{
    items.push({caption: this.data[j].channelName, value: this.data[j].channelId});
}
this.$.mySelector.setItems( items );
于 2011-09-08T22:12:17.810 回答