简体   繁体   English

流星-将数据传递到模板

[英]Meteor - Pass data to template

I'm using Iron:Router and i have the following event in my template. 我正在使用Iron:Router,并且我的模板中有以下事件。

If the Guests.update function successful I want to redirect to the thanks template with the given properties. 如果Guests.update函数成功,我想重定向到具有给定属性的thanks模板。

How can I receive the success property in my thanks template to use it there? 如何在我的thanks模板中接收success属性以在其中使用?

Template.guest.events({
  'submit form': function(event, template){
    event.preventDefault();
    var foo = $('[name=foo]').val();
    Guests.update(this._id, {
      $set: {
        foo: foo,
      }
    }, function(error, result){
      if (error) {
        console.log(error);
      } else {
        Router.go('thanks', { success:true, id: this._id } });
      }
    });
  }
});

Add parameters to your route definition: 向您的路线定义添加参数:

Router.route('/thanks/:success/:_id', function () {
  let success = this.params.success;
  let _id = this.params._id;
  ...
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM