0

我正在开发 Windows Store App/Metro UI 应用程序,它从 AppSettings 获取数据并将这些数据绑定到 ListView 中。这是data.js的代码

(function () {
    "use strict";

    var dataSource = new Array();
    var dataList = new WinJS.Binding.List();

    var appData = Windows.Storage.ApplicationData.current;
    var roamingSettings = appData.localSettings;
    var json = roamingSettings.values["reminderList"];
    if (json != undefined) {
        dataSource = JSON.parse(json);


        for (var i in dataSource) {
            var rem = dataSource[i];
            dataList.push(rem);
        }

    }
    // Create a namespace to make the data publicly
    // accessible. 
    var publicMembers =
        {
            itemList: dataList
        };
    WinJS.Namespace.define("MyData", publicMembers);
})();

这是我使用的 ListView 的代码。

<div id="basicListView" data-win-control="WinJS.UI.ListView" 
            data-win-options="{ itemDataSource : MyData.itemList.dataSource, itemTemplate:select('#mediumListIconTextTemplate') }">

但是当存储中有一项时,它在 ListView 中显示为未定义。当 AppSettings 中有多个项目时,它会给我以下错误。

{
    "exception": null,
    "error": [
        [{
            "description": "Out of stack space",
            "number": -2146828260,
            "stack": "Error: Out of stack space\n   at getProperty (ms-appx://microsoft.winjs.1.0/js/base.js:8283:13)\n   at get (ms-appx://microsoft.winjs.1.0/js/base.js:8566:36)\n   at getProperty (ms-appx://microsoft.winjs.1.0/js/base.js:8283:13)\n   at get (ms-appx://microsoft.winjs.1.0/js/base.js:8566:36)\n   at getProperty (ms-appx://microsoft.winjs.1.0/js/base.js:8283:13)\n   at get (ms-appx://microsoft.winjs.1.0/js/base.js:8566:36)\n   at getProperty (ms-appx://microsoft.winjs.1.0/js/base.js:8283:13)\n   at get (ms-appx://microsoft.winjs.1.0/js/base.js:8566:36)\n   at getProperty (ms-appx://microsoft.winjs.1.0/js/base.js:8283:13)\n   at get (ms-appx://microsoft.winjs.1.0/js/base.js:8566:36)"
        }]
    ],
    "promise": {
        "_oncancel": null,
        "_nextState": null,
        "_state": {
            "name": "error",
            "done": null,
            "then": null
        },
        "_listeners": null,
        "_value": [
            [{
                "description": "Out of stack space",
                "number": -2146828260,
                "stack": "Error: Out of stack space\n   at getProperty (ms-appx://microsoft.winjs.1.0/js/base.js:8283:13)\n   at get (ms-appx://microsoft.winjs.1.0/js/base.js:8566:36)\n   at getProperty (ms-appx://microsoft.winjs.1.0/js/base.js:8283:13)\n   at get (ms-appx://microsoft.winjs.1.0/js/base.js:8566:36)\n   at getProperty (ms-appx://microsoft.winjs.1.0/js/base.js:8283:13)\n   at get (ms-appx://microsoft.winjs.1.0/js/base.js:8566:36)\n   at getProperty (ms-appx://microsoft.winjs.1.0/js/base.js:8283:13)\n   at get (ms-appx://microsoft.winjs.1.0/js/base.js:8566:36)\n   at getProperty (ms-appx://microsoft.winjs.1.0/js/base.js:8283:13)\n   at get (ms-appx://microsoft.winjs.1.0/js/base.js:8566:36)"
            }]
        ],
        "_isException": false,
        "_errorId": 7
    },
    "id": 7
}

谁能指点我一个解决方案。

4

1 回答 1

0

你的模板mediumListIconTextTemplate看起来如何?它是否与您用于构建数据列表的 JSON 对象匹配?我怀疑它是。

此外,当您说引发错误时,您能否提供堆栈跟踪?

如果您发布示例 JSON 以及mediumListIconTextTemplate.

于 2012-10-21T13:08:06.287 回答