windows 8 - WinJS - Adding 'selected' style to first item in listview on load -
i'm trying @ present use listview drive content of separate div in windows store app (html/js).
i have simple function call inside 'oniteminvoked' handler listview.
method call
myapp.util.addclassbyid(q(".item"), item.itemid, "selected");
(where item.itemid of newly selected item , 'q' alias winjs.utilities.query)
method declaration
function addclassbyid(elements, selectedid, classname) { elements.foreach(function (el) { var id = parseint(el.attributes['data-id'].value, 10); if (id === selectedid) { util.addclass(el, classname); } else { util.removeclass(el, classname); } }); }
this works expected after listview loaded , i'm selecting new items. doesn't load when try call during ready
function page in question.
when go through in debug, seems query items in list doesn't return during pages ready
function, i'm assuming list hasn't been rendered @ point , dom query returns nothing.
so question this, what's recommended approach select item (or perform action on listview) after it's been rendered?
i thought might 'afterrender' type event call function can't seem find works.
any ideas?
the best way know of capture onloadingstatechanged
event , wait until listview has been "loaded". can see how visiting blog post @ http://codefoster.com/loadingstates
Comments
Post a Comment