Answered by:
Listview. Binding an array obtained programatically.

Question
-
I am trying to use listview template to display the best scores in a game.
I can retrieve the scores, but cannot bind them.
var scores= {}; var scored = new Object(); function getScores() { document.getElementById('basicListViewb').style.display = "block"; var roamingSettings = Windows.Storage.ApplicationData.current.roamingSettings; var scoreArray = roamingSettings.createContainer("scores", Windows.Storage.ApplicationDataCreateDisposition.Always); for (var x = 0; x < 12; x++) { scoress[x] = { title: x, time: scoreArray.values[x] }; } scored = new WinJS.Binding.List(scoress); } WinJS.Namespace.define("getScores", { getScores: getScores, scored: scored });
scores[] is as it should be, but scored is empty.
I have tried with the quickstart sample, substituting a static array in the getScores function. I have the same problem. It works OK when the array is outside of any functions.
The best scores can obviously change during a game so I do not want to call the array until it is needed.
Is there any way to get round this please?
Many thanks.
Saturday, September 13, 2014 9:30 PM
Answers
-
Have finally got a couple of steps further using WinJS.Binding.as.
I am now getting data.stack "TypeError: Object doesn't support property or method 'createListBinding'\n at ItemsManager_ctor (ms-appx://microsoft.winjs.2.0/js/ui.js:10638:17)\n at Anonymous function (ms-appx://microsoft.winjs.2.0/js/ui.js:11392:17)\n at ListView_updateItemsManager (ms-appx://microsoft.winjs.2.0/js/ui.js:24473:21)\n at ListView_ctor (ms-appx://microsoft.winjs.2.0/js/ui.js:22919:17)\n at activate2 (ms-appx://microsoft.winjs.2.0/js/base.js:4681:17)\n at Promise_ctor (ms-appx://microsoft.winjs.2.0/js/base.js:2025:17)\n at activate (ms-appx://microsoft.winjs.2.0/js/base.js:4653:9)\n at processAllImpl2 (ms-appx://microsoft.winjs.2.0/js/base.js:4749:21)\n at Promise_ctor (ms-appx://microsoft.winjs.2.0/js/base.js:2025:17)\n at processAllImpl (ms-appx://microsoft.winjs.2.0/js/base.js:4692:9)" String
Can anyone enlighten me further please? Many thanks.
here is the code:
<div id="scorepage" data-win-control="WinJS.UI.ListView" data-win-options="{ selectionMode: 'none', itemDataSource: getScores.scoreList, itemTemplate: select('#scoretemplate'), layout: {type: WinJS.UI.GridLayout}}"> </div> <div id="basicListViewb" data-win-control="WinJS.UI.ListView" data-win-options="{ itemDataSource : getScores.scoreList.dataSource }"> </div>
var dataList = new Object(); var scoreList = {}; var scored = new WinJS.Binding.List(); function getScores() { document.getElementById('basicListViewb').style.display = "block"; var roamingSettings = Windows.Storage.ApplicationData.current.roamingSettings; var scoreArray = roamingSettings.createContainer("scores", Windows.Storage.ApplicationDataCreateDisposition.Always); for (var x = 0; x < 12; x++) { scored.push(WinJS.Binding.as({ title: x, time: scoreArray.values[x] })) } scoreList = scored.dataSource; //IListDataSource } WinJS.Namespace.define("getScores", { getScores: getScores, scored: scored, scoreList: scoreList })
- Marked as answer by chickfeed Monday, September 15, 2014 10:01 AM
Monday, September 15, 2014 9:43 AM
All replies
-
Hi chickfeed,
You mentioned "It works OK when the array is outside of any functions", if you assign the value from function to the outside array, will it works fine?
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.Monday, September 15, 2014 9:08 AMModerator -
Have finally got a couple of steps further using WinJS.Binding.as.
I am now getting data.stack "TypeError: Object doesn't support property or method 'createListBinding'\n at ItemsManager_ctor (ms-appx://microsoft.winjs.2.0/js/ui.js:10638:17)\n at Anonymous function (ms-appx://microsoft.winjs.2.0/js/ui.js:11392:17)\n at ListView_updateItemsManager (ms-appx://microsoft.winjs.2.0/js/ui.js:24473:21)\n at ListView_ctor (ms-appx://microsoft.winjs.2.0/js/ui.js:22919:17)\n at activate2 (ms-appx://microsoft.winjs.2.0/js/base.js:4681:17)\n at Promise_ctor (ms-appx://microsoft.winjs.2.0/js/base.js:2025:17)\n at activate (ms-appx://microsoft.winjs.2.0/js/base.js:4653:9)\n at processAllImpl2 (ms-appx://microsoft.winjs.2.0/js/base.js:4749:21)\n at Promise_ctor (ms-appx://microsoft.winjs.2.0/js/base.js:2025:17)\n at processAllImpl (ms-appx://microsoft.winjs.2.0/js/base.js:4692:9)" String
Can anyone enlighten me further please? Many thanks.
here is the code:
<div id="scorepage" data-win-control="WinJS.UI.ListView" data-win-options="{ selectionMode: 'none', itemDataSource: getScores.scoreList, itemTemplate: select('#scoretemplate'), layout: {type: WinJS.UI.GridLayout}}"> </div> <div id="basicListViewb" data-win-control="WinJS.UI.ListView" data-win-options="{ itemDataSource : getScores.scoreList.dataSource }"> </div>
var dataList = new Object(); var scoreList = {}; var scored = new WinJS.Binding.List(); function getScores() { document.getElementById('basicListViewb').style.display = "block"; var roamingSettings = Windows.Storage.ApplicationData.current.roamingSettings; var scoreArray = roamingSettings.createContainer("scores", Windows.Storage.ApplicationDataCreateDisposition.Always); for (var x = 0; x < 12; x++) { scored.push(WinJS.Binding.as({ title: x, time: scoreArray.values[x] })) } scoreList = scored.dataSource; //IListDataSource } WinJS.Namespace.define("getScores", { getScores: getScores, scored: scored, scoreList: scoreList })
- Marked as answer by chickfeed Monday, September 15, 2014 10:01 AM
Monday, September 15, 2014 9:43 AM -
Solved!
The second error was extraneous html.
I think I am on the home straight with this bit.
Monday, September 15, 2014 10:01 AM