javascript - Loop through jQuery Mobile list view data attribute -


i'm trying loop through data attribute of jquery mobile listview, can last element, , don't know why.

 var listitems = $("li.placeslist"); listitems.each(function (idx, li) {     var $this = $(li);     console.log($this.attr("id")); // works expected. shows ids     console.log($this.data('distancia')); //it shows last item's data value  of list  }); 

the way i'm assigning data value in part of code is:

 $('<li class="placeslist"></li>').data({     location: pointsarray[pointcount].location,     distancia: distancia }); 

i know data being added correctly.

in console see

correct values:

0.409  0.26  

using $each() loop, see 3 correct ids, data of last element:

a //id 0.26  b //id 0.26  

what doing wrong? in advance.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -