首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在rails + Backbone.js应用程序中使用jQuery raty插件

无法在rails + Backbone.js应用程序中使用jQuery raty插件
EN

Stack Overflow用户
提问于 2015-02-05 13:31:50
回答 1查看 304关注 0票数 0

我使用的是来自http://www.wbotelhos.com/raty的Jquery raty插件。我有一个Rails + Backbone.js评论应用程序,每当我添加评论表单视图时,当我将鼠标悬停在它们上面时,我就无法让任何星星“打开”。该插件适用于只读评级,但不适用于添加评级。下面是我的表单子视图代码: //reviews_form.js

代码语言:javascript
复制
App.Views.ReviewsForm = Backbone.CompositeView.extend({

    initialize: function(options){
        this.business = options.business;
    },

    template: JST['reviews/form'],
    events: {
        "click #review-submit":"submitForm"
    },
    render: function(){
      var renderedContent = this.template()
      this.$el.html(renderedContent);
      $inputRating = this.$el.find('#input-rating');
        $inputRating.raty();
      return this;
    },

    submitForm: function(event){
        event.preventDefault();
        this.model.reviews().create({
            rating: $('#input-rating').val(), 
            content: this.$(".review_content").val(), 
            business_id: this.business.id
        }, { wait: true });
        $(".review_content").empty(); 
    }
})

我通过下面的代码在business_show.js文件中添加了评论表单视图:

代码语言:javascript
复制
addReviewForm: function(review){
        var reviewsForm = new Expecto.Views.ReviewsForm({model: this.model, business: this.model});
        this.addSubview(".reviews-form", reviewsForm)
    }, 

我的表单模板如下:

代码语言:javascript
复制
<h3 class="user-reviews">Add a review</h3>
<form class="form-horizontal" id="new-review-form">
 <div class="form-group">


    <div id="input-rating"></div>
    <label>Review</label><br>
    <textarea name="review[content]" class="review_content" style="width: 500px; height: 150px;"></textarea><br>
    <input type="hidden" name="review[business_id]" value="<%= this.business_id %>">
    <input type="hidden" name="review[user]" value="<%= this.user %>">
    <button id="review-submit" class=" btn btn-primary">Submit</review>
    </div>
</form>
EN

回答 1

Stack Overflow用户

发布于 2015-03-20 09:57:15

我相信你实际上需要传入一个回调函数让raty使用onClick。从拉蒂的文档里。

代码语言:javascript
复制
$('div').raty({
  click: function(score, evt) {
  alert('ID: ' + this.id + "\nscore: " + score + "\nevent: " + evt);
  }
});

所以在你的例子中,只需要放一个函数来设置一个评级的值,来给this.val(score)打分。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28336836

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档