0
我在我的骨干项目中使用Jquery rateIt插件。Jquery rateIt插件不工作
我正在使用它的AJAX示例部分。
我能看到图像加载没有呼叫经历和没有任何反应,一段时间后得到错误像
“遗漏的类型错误:对象rateAnswer有没有方法‘应用’”
这里是我的JS
define(['jquery', 'underscore', 'backbone', 'text!tpl/questionnaire.html', 'Collection/cAppCollection', 'Models/mAppModel', 'jqueryRateIt'],
function($, _, Backbone, questionnaireTpl, appCollection, appModel, jqRateIt) {
var questionnaire = Backbone.View.extend({
el : '.row',
template : _.template(questionnaireTpl),
initialize : function(e) {
$('.hero-unit').css('display','none');
this.render(e);
},
//this renders my template
//on success of response , loads response than call rateit() function than bind rated and reset to function rateAnswer
//but here no call fo rateAnswer
render : function(e) {
var elem = this.$el,
temp = this.template,
appCollectObj = new appCollection();
appCollectObj.fetch({
data: $.param({subject: e.id}),
success: function(model, response) {
$(elem).html(temp({model:response}));
$('div.rateit').rateit();
$('#products .rateit').bind('rated reset', 'rateAnswer');
},
error: function() {
console.log('Failed to fetch!');
}
});
},
rateAnswer : function(){
var ri = $(this),
appCollectObj = new appCollection();
var value = ri.rateit('value');
var questionId = ri.data('productid');
appCollectObj.fetch({
data: $.param({questionId : questionId, value : value}),
success: function(model, response) {
$('#response').append('<li>' + data + '</li>');
},
error: function() {
$('#response').append('<li style="color:red">' + msg + '</li>');
}
});
}
});
return questionnaire;
});
和HTML部分是
<div id="products">
<ul>
<li>
RateIt: <div data-productid="<%= elem.id %>" class="rateit"></div>
</li>
</ul>
<ul id="response"></ul>
</div>
here the link to RateIt plugin example
尝试$ .proxy(this.rateAnswer,this)以及$ .proxy(this.rateAnswer,this)仍然没有调用函数rateAnswer – mayank
$('#products .rateit')。bind('rated reset' ,'rateAnswer');在这里传递字符串而不是函数是我的不好的感谢修正。现在我没有错误,但没有呼吁绑定功能 – mayank
啊,我的坏,我做了太多的咖啡标记(和它美丽的胖箭头)。你已经在回调,所以'这'已经'错误'了。我编辑了我的答案。 – Enders