0

テンプレートを介してデータを渡したいのですが、未定義になっています顧客テンプレート内に2つの変数があり、ユーザーがクリックすると、これら2つの変数を次のテンプレートcustomerchathstoryに渡したいです

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 内でこれらの 2 つの変数を取得しているとき、未定義になっています

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

1 に答える 1

0

Blaze html テンプレートで使用できるように、ヘルパーRidで変数を定義する必要があります。Rtoken

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 に答える