2011-09-08 80 views
0

所有動態ListSelector陣列問題

我現在的工作日內的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' 替換所有項目的動態方式。它只顯示我的db的最後一個值。

回答

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); 
+0

Thanks Pre,會記住items.push。謝謝 –