Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Re : how should I write a star rating component

$
0
0
I would only have 2 values, rating and stars.  I'd have a "count" helper like:

count: function(num, options){
  var res = "";
  num = num();
  for(var i =0; i < num; i++){
     res += options.fn({"@index": i})
  }
  return res;
}

and a "lessThan" helper like:

lessThan: function(a,b, options){
  return a() < b ? options.fn(options.scope) : options.inverse(options.scope);
}

And a template like:

{{#count stars}}
  {{#lessThan rating @index}}
    <img for solid star>
  {{else}}
    <img for empty star can-click="updateRating">
  {{/lessThan}}
{{/count}}

Viewing all articles
Browse latest Browse all 3491

Trending Articles