【问题标题】:Want to fill WinJS.UI.ListView with my own data想用我自己的数据填充 WinJS.UI.ListView
【发布时间】:2013-04-07 16:35:16
【问题描述】:

我使用

获得了数据
WinJS.xhr({ url: url, responseType: "json" }).then(
     function(result){},
     function(error){}
);

我在按钮点击事件中制作这些东西。 我正确获取了数据,但无法将它们填充到我的 ListView 中。 那么现在,如何在每次单击按钮时将我的 WinJS.UI.ListView 中的 JSON 数据与我的新数据绑定......?请通过一些简单的例子帮助我。因为我已经检查了很多链接。但我还是不明白在哪里

【问题讨论】:

    标签: winjs


    【解决方案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
    });
    

    【讨论】:

    • 我收到此错误:异常即将被 JavaScript 库代码在 ms-appx://microsoft.winjs.1.0/js/ui.js 0x800a01b6 - JavaScript 中的第 10299 行第 5 列捕获运行时错误:对象不支持属性或方法“createListBinding”
    • 这是我的 ListView 控件:
    • 没有这行它不会给我任何错误或异常:listView.winControl.itemDataSource = list;
    • 哎呀错过了list.dataSource
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-06
    相关资源
    最近更新 更多