将分数变量传递给jqueryraty
我正在使用 jqueryraty 为我的 ruby on Rails 网站实现星级评定和分数显示。我可以使用该插件接受投票,但是在从数据库检索分数后我不得不显示分数。假设我需要显示来自数据库的投票,投票用户和分数存储在一个变量中,比如@user.score(例如@user.score = 3)。
- 以 .erb 形式显示星星的语法是什么?我知道如果分数是一个常数,例如 3,我可以写如下:
$('#star').raty({
readOnly: true,
start: 3
});<div><div id="star"></div>
或者
$('#start').raty({ start: function() { return $(this).attr('data-rating'); } }); <div id="star" data-rating="3"></div>
但是现在分数值 3 存储在 @user.score (变量)中。如何将分数值传递到星星显示?
公共函数$('#star').raty('score');看起来它正在对分数做一些事情,但我不明白它在做什么。可以告诉我吗?
也许我显示检索到的分数的方向错误。请告诉我。
请帮忙 谢谢 炮台
I am using jquery raty to implement star rating and score display for my ruby on rails site. i can use the plugin to accept votes however i am stuck to display the scores after they are retrieved from the DB. Say i need to show a vote from the DB, the voting user and the score are stored in a variable say @user.score (e.g. @user.score = 3).
- What is the syntax to display the stars in the .erb form? I know if the score is a constant, e.g. 3, I can write something like:
$('#star').raty({
readOnly: true,
start: 3
});
<div><div id="star"></div>
OR
$('#start').raty({
start: function() {
return $(this).attr('data-rating');
}
});
<div id="star" data-rating="3"></div>
But now the score value 3 is stored in @user.score (a variable). How can I pass the score value to the star display?
Public function $('#star').raty('score'); looks like it is doing something to the score but I don't understand what it is doing. Can tell me?
Maybe I am in a wrong direction to display the retrieved score. Please tell me.
Please help
Thanks
batterhead
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正确的答案似乎是:
所以,你可以这样做
The correct answer would appear to be:
so, you can do
这是
.raty()
插件的 文档页面。在我看来,有几个示例说明如何使用初始值初始化给定的一组评级。以下是其中一个示例:如果您的分数位于名为
myScore
的变量中,则可以执行以下操作:Here's the doc page for the
.raty()
plugin. It looks to me like there are several examples for how to initialize a given set of ratings with it's initial value. Here's one of those examples:If you have the score in a variable named
myScore
, you can do this: