Very confused, hope someone can help to understand why I'm getting different results when running in JS vs Apperyio model?
As you can see on the results, when using Apperyio approach, it saves 4 times but always has the last ( page4) page for some reason.
Model :
Storage:
Code :
function check_service_selections(){
Code: Select all
var service_selections = ['page1', 'page2', 'page3', 'page4'];
var service_list_obj = {}; // JS object
var ServiceList = Apperyio.getModel('ServiceList'); // Appery model
$.each(service_selections, function(key, value){
var service_obj = {};
var Service = Apperyio.getModel('Service');
Service.page = value;
Service.status = 0;
service_obj.page = value;
service_obj.status = 0;
service_list_obj[key] = service_obj;
ServiceList[key] = Service;
});
// save in storage
Apperyio.storage.service_list.set(service_list_obj);
// read from storage
console.log(Apperyio.storage.service_list.get()); // this prints an array of objects, which is what I expect
// This part of the code doesn't work as it should. All objects have the same ( last ) page name, in this case, page4
// save in storage
Apperyio.storage.service_list.set(ServiceList);
// read from storage
console.log(Apperyio.storage.service_list.get()); // this also returns an array of objects, but every object has the same "page" name
}
Results :
Thanks!