0

我想通过模板传递数据,但我得到未定义我在客户模板中有两个变量,当用户单击时,我想将这两个 var 传递给下一个模板 customerchathistory,例如

Template.customer.events({
  async 'click .list-chat'(event,template) {
    const Rid = event.currentTarget.id;
    const Rtoken = event.currentTarget.token;
 }
})

在这里,我在 customer.html 中传递了像这样的变量

{{>cutomerChatHistory clickRid= Rid clickRtoken = Rtoken }}

现在,当我在 customerChatHistory.js 中获取这两个变量时,我变得未定义

Template.customerChatHistory.onCreated(function() {
 const currentData = Template.currentData();
console.log(currentData.clickRid , currentData.clickRtoken) //giving undefined here
})
4

1 回答 1

0

您需要在帮助程序中定义RidRtoken变量,以便它们在 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)
})
于 2020-05-15T11:00:16.067 回答