Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

looping through a storage model

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?

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

looping through a storage model

Hello Terry,

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

Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

looping through a storage model

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

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

looping through a storage model

Thank you for update! Glad it works now!

Return to “Issues”