我想通过模板传递数据,但我没有定义。我在客户模板中有两个变量,当用户单击时,我想将这两个变量传递给下一个模板客户聊天历史,如
Template.customer.events({
async 'click .list-chat'(event,template) {
const Rid = event.currentTarget.id;
const Rtoken = event.currentTarget.token;
}
})
在这里,我在customer.html 中传递这样的var
{{>cutomerChatHistory clickRid= Rid clickRtoken = Rtoken }}
现在,当我在customerChatHistory.js中获取这两个var时,我得到了未定义的
Template.customerChatHistory.onCreated(function() {
const currentData = Template.currentData();
console.log(currentData.clickRid , currentData.clickRtoken) //giving undefined here
})
您需要在助手中定义Rid
和Rtoken
变量,以便它们在Blaze html模板中可用:
Template.customer.events({
async 'click .list-chat'(event,template) {
template.Rid.set(event.currentTarget.id);
template.Rtoken.set(event.currentTarget.token);
}
})
Template.customer.helpers({
Rid: function(){
return Template.instance().Rid.get();
}
Rtoken: function(){
return Template.instance().Rtoken.get();
}
})
Template.customer.onCreated({
this.Rid = new ReactiveVar(null)
this.Rtoken = new ReactiveVar(null)
})