here have code convert number(rating) stars using http://wbotelhos.com/raty, http://wbotelhos.com/raty/lib/jquery.raty.min.js
i create jsfiddle: http://jsfiddle.net/3sxke/4/
// mocking supposed "place" variable var place = { name: "james cook hotel grand chancellor", rating: "3.6", photos: [{ geturl: function () { return "https://lh6.googleusercontent.com/-t0_fjx5zza0/udsnoauczvi/aaaaaaaaafc/gqhk3ibhjfy/w50-h50-s0/small%2blogo.png" } }] } var photo = place.photos[0].geturl({ 'maxwidth': 50, 'maxheight': 50 }); var elemenatdiv = $('<div>').addclass('elemenat'); var draggablediv = $('<div>').addclass('draggable'); var logo = $('<img>').css({'margin-left': '3px', 'margin-top': '5px'}) .attr('src', photo).attr('width', 46).attr('height', 42) var sideclick = $("<a>").addclass('side_click').attr('href', '#') .text(place.name + place.rating); var elementnamediv = $('<div>').addclass('elementname'); var star = $('#star').raty({ score: place.rating }); elemenatdiv.append(draggablediv.append(logo)); elemenatdiv.append(elementnamediv.append(sideclick).append(star)); $("#side_bar").append(elemenatdiv); $(sideclick).on("click", function () { markers[i].modalwindow_.getdetails(markers[i].place_); });
and use first: var star = $('#star').raty({ score: place.rating });
, after append elemenatdiv.append(elementnamediv.append(sideclick).append(star));
but star rating won't show when render html code?
i try different solution dont know error?
this line problem:
var star = $('#star').raty({ score: place.rating });
you trying select dom element id (#star
), there no element in dom.
you need inject div id of star
dom.
Comments
Post a Comment