Page 1 of 1

looping through a storage model

Posted: Wed Jun 15, 2016 3:15 pm
by Terry Gilliver

I have a model trader defined as an object, and a session store called trader which if of type 'trader'.

Image

Image

I want to loop through the object items in javascript, how is this accomplished?


looping through a storage model

Posted: Wed Jun 15, 2016 3:41 pm
by Serhii Kulibaba

Hello Terry,

Please use for..in statement for that: https://developer.mozilla.org/en/docs...


looping through a storage model

Posted: Wed Jun 15, 2016 4:41 pm
by Terry Gilliver

Thanks, Sergiy,

I have it working now here is the solution to my issue of checking completeness of a trader profile:

//this indicates how complete a profile is:
//There are 20 profile items, so for every completed item
//we add 5%. This is than saved in the list item counter value

var profileCompleteness = 0, key;

for (key in Apperyio.storage.trader.get()) {
console.log("key = ", key);

if (Apperyio.storage.trader.get("$['" + key + "']") !== "") {
profileCompleteness += 5;
}
}

$("span.ui-li-count").text(profileCompleteness.toString() + "%");

Image


looping through a storage model

Posted: Wed Jun 15, 2016 6:00 pm
by Serhii Kulibaba

Thank you for update! Glad it works now!