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

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -