【问题标题】:How to pass variable through template Data in meteor js?如何通过流星js中的模板数据传递变量?
【发布时间】:2020-08-21 04:35:38
【问题描述】:

我想通过模板传递数据,但我得到未定义我在客户模板中有两个变量,当用户单击时,我想将这两个变量传递给下一个模板 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 中获取这两个 var 时,我变得未定义

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

【问题讨论】:

  • 请添加两个模板的 html 文件,否则不清楚您将哪些数据传递到哪里。

标签: javascript meteor meteor-blaze blaze


【解决方案1】:

您需要在帮助程序中定义 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)
})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-07-19
    • 1970-01-01
    • 2014-08-22
    • 2023-03-24
    • 1970-01-01
    • 2013-11-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多