Javascript 获取template.foo.rendered中集合实例的。\u id
我尝试将semanticui()中的评级模块包含在文章下面,以便用户能够对其进行评级。如果用户对文章进行评分,则文章id将存储在Meteor.user().profile.ratedItems中 如果用户从一篇文章转到另一篇文章,然后又回到第一篇文章,则评级模块应呈现为只读(因此用户无法再次对同一篇文章进行评级) 问题是,我不知道如何检查template.foo.rendered中的Meteor.user().profile.ratedItems中是否存储了article\u id,因为该.u id给出的不是article id,而是模板的id 在template.foo.events和template.foo.helpers中,我可以通过以下句子来检查是否存在此问题:Meteor.user()。现在,即使用户对一篇文章的评分超过一次,以db为单位的评分也不会改变。但我需要解决“视觉”问题 下面是代码: JS: HTML:Javascript 获取template.foo.rendered中集合实例的。\u id,javascript,mongodb,templates,meteor,semantic-ui,Javascript,Mongodb,Templates,Meteor,Semantic Ui,我尝试将semanticui()中的评级模块包含在文章下面,以便用户能够对其进行评级。如果用户对文章进行评分,则文章id将存储在Meteor.user().profile.ratedItems中 如果用户从一篇文章转到另一篇文章,然后又回到第一篇文章,则评级模块应呈现为只读(因此用户无法再次对同一篇文章进行评级) 问题是,我不知道如何检查template.foo.rendered中的Meteor.user().profile.ratedItems中是否存储了article\u id,因为该.u
{{{#if currentUser}{{statetext}{{else}}总体评级:{{/if}
我考虑过使用Session.set和Session.get,但还没有找到任何解决方案。
提前感谢您的帮助。您可以在
呈现的
回调中使用模板.currentData
,而不是此
请参见。中的文档,而不是
此
,您可以在呈现的回调中使用模板.currentData
请参见。中的文档,而不是此
,您可以在呈现的回调中使用模板.currentData
请参见。中的文档,而不是此
,您可以在呈现的回调中使用模板.currentData
请参阅位于的文档。谢谢。我会尝试一下,如果它对我有效,我会接受答案。我刚刚将Template.foo.rendered中的\u id
更改为Template.currentData()。\u id
,效果很好。谢谢,谢谢。我会尝试一下,如果它对我有效,我会接受答案。我刚刚将Template.foo.rendered中的\u id
更改为Template.currentData()。\u id
,效果很好。谢谢,谢谢。我会尝试一下,如果它对我有效,我会接受答案。我刚刚将Template.foo.rendered中的\u id
更改为Template.currentData()。\u id
,效果很好。谢谢,谢谢。我会尝试一下,如果它对我有效,我会接受答案。我刚刚将Template.foo.rendered中的\u id
更改为Template.currentData()。\u id
,效果很好。非常感谢。
Template.foo.helpers({
rate: function () {
return Math.floor(this.rating);
},
state : function () {
if (Meteor.userId()) {
if (_.contains(Meteor.user().profile.ratedItems,this._id)) {
return "rated"
} else {return "unrated"}
} else {
return ""
}
},
statetext: function () {
if (Meteor.userId()) {
if (_.contains(Meteor.user().profile.ratedItems,this._id)) {
return "Overall rating:" }
else { return "Rate the article:"}
} else {
return "Overall rating:"
}
}
});
Template.foo.rendered = function() {
if (Meteor.userId()) {
if (_.contains(Meteor.user().profile.ratedItems,this._id)) {
$('.ui.rating').rating('disable');
} else {
$('.ui.rating').rating();
}
} else {
$('.ui.rating').rating('disable');
}
};
Template.foo.events({
'click .unrated': function () {
var addedRating = $('.unrated').rating('get rating');
var currentArticleId = this._id;
var newsum = this.rating_sum+addedRating;
var newcount = this.rating_count+1;
var newrating = newsum/newcount;
Schools.update(currentSchoolId,{$inc: {rating_count:1}});
Schools.update(currentSchoolId,{$inc: {rating_sum:addedRating}});
Schools.update(currentSchoolId,{$set: {rating:newrating}});
Meteor.users.update({_id:Meteor.userId()},{$push: {'profile.ratedItems':currentArticleId}});
$('.ui.rating').rating({"set rating":Math.floor(newrating)});
$('.ui.rating').rating('disable');
}
});
<template name="schoolPage">
<div class="ui center aligned blue segment">
{{#if currentUser}}{{statetext}}{{else}}Overall rating:{{/if}}
<div class="ui tiny heart rating {{state}}" data-rating="{{rate}}" data-max-rating="5"></div>
</div>
</template>