2013-04-07 36 views
0

我一直在使用想用我自己的數據來填充WinJS.UI.ListView

WinJS.xhr({ url: url, responseType: "json" }).then(
    function(result){}, 
    function(error){} 
); 

我就按一下按鈕事件這些東西獲得了數據。 我得到了正確的數據,但無法填充他們在我的ListView。 所以,現在,我怎樣才能綁定我的WinJS.UI.ListView JSON數據每次點擊按鈕與我的新數據...?請用一些簡單的例子來幫助我。因爲我已經檢查了很多鏈接。但我還是不明白其中

回答

1

它應該是這樣的:

WinJS.xhr({ .. }).then(function xhrcomplete(req) 
{ 
    var data; // assuming you already have code that parsed json text to an object. 
    var items = []; 
    // fill code here to get items out of the data 
    var list = new WinJS.Binding.List(items); 
    // binding code will depend on whether listview has groupHeaderTemplate or not 
    // if not - it should be like this 
    listView.winControl.itemDataSource = list.dataSource; // listView is the id of the your list view control in html 

}).then(null, function onerror(error) 
{ 
    // handle error case 
}); 
+0

我得到這個錯誤:在異常即將被由JavaScript庫代碼的行10299抓,列5 MS-APPX: //microsoft.winjs.1.0/js/ui.js 0x800a01b6 - JavaScript運行時錯誤:對象不支持屬性或方法'createListBinding' – 2013-04-07 08:23:36

+0

這是我的ListView控件:

2013-04-07 08:25:57

+0

沒有這條線它沒有給我任何種類錯誤或異常:listView.winControl.itemDataSource = list; – 2013-04-07 08:28:53

相關問題