I’m new to windows 8 metro style app development and I come from PHP based web application development background.
Now, in my app I fetch data using WinJS.xhr and add it to WinJS.Binding.List list. The problem is when I revisit the page, the old data acquired from the previous xhr code is still there and the new data appends to this list.
How to rectify this?
EDIT
Homedeliverydata.js file
var list = new WinJS.Binding.List();
var groupedItems = list.createGrouped(
function groupKeySelector(item) { return item.group.key; },
function groupDataSelector(item) { return item.group; }
);
function getFeaturedRestaurants(city_id) {
Utilities.featuredRestaurants(city_id, 'home_delivery').
then(function onComplete(result) {
var restaurants = result.result;
for (var i = 0; i < restaurants.length; i++) {
restaurants[i].group = Groups[0];
restaurants[i].key = restaurants[i].id;
list.push(restaurants[i]);
}
},
function onError() {
}, function onProgress() {
});
}
function clearData() {
list.splice(0, list.length);
list._currentKey = 0;
}
HomeDelivery.js
ready: function (element, options) {
//code above this line removed
HomeDeliveryListdata.GetSearchData(params).then(afterCall, function (req) { }, function (req) { });
},
unload: function () {
HomeDeliveryListdata.clearData();
}
The list will last the lifetime of the variable it is being assigned to. In addition, if you are using the single page model for you app (the default, recommended way), then the variable containing the list will likely survive from page to page.
If you want the existing list to be replaced each time you visit a page, make sure that you are scoping the lifetime of the list appropriately (usually scoping the list to the success promise of the xhr request is sufficient) or writing code to clear and refresh the list.
Hard to point out the exact fix without example code, but hopefully that will help you fix the problem.