barbatus / stars-rating

Stars rating control for Meteor
MIT License
21 stars 11 forks source link

Unable to fetch the value of stars #16

Open prats8m opened 8 years ago

prats8m commented 8 years ago

It looks like i m unable to fetch the value of stars by id or by currentTarget method. i follow the exact code as written in the description.please help.

Karan80 commented 8 years ago

Add the id.The unique id is the id that Mongodb provides {{> starsRating id=_id mutable=true}} Here we are working with the template. For example - if there is an image template and you have lots of images. Each image will have a unique id so this id will be same for the starRating template.

code example -

<template name="images">
<div class="col-xs-12" id="{{_id}}">
    <div class="thumbnail">

        <img class="js-image" src="{{img_src}}" 
        alt="{{img_alt}}" /> 

        <div class="caption">
                    <h3>Rating: {{rating}}</h3>
               <p>{{img_alt}}</p>

           <p>
            {{>starsRating mutable=true class="js-rate-image" id=_id}}
          </p>
</div>
</template>

Then apply a class to your starsRating template like {{>starsRating mutable=true class="js-rate-image" id=_id}}. Now you can modify its behaviour in the js file like

var rating = $(event.currentTarget).data("userrating"); . Now update using update method in mongo.

And don't forget mutable="true" as this will allow the user to set a rating.

domoran commented 8 years ago

Put this to the documentation:

To get the value of the current rating from javascript use inside the change callback: $(event.currentTarget).data("userrating");