gpt4 book ai didi

javascript - 如何在 Meteor 上使用 IronRouter 在操作中设置数据?

转载 作者:行者123 更新时间:2023-12-02 18:10:47 25 4
gpt4 key购买 nike

如何在 Meteor Application 的操作函数中设置附加数据使用 IronRouter ?请参阅下面的 emailWelcome 和 emailContract 函数中的评论...

代码:

EmailController = RouteController.extend({
template: 'emailPage',

waitOn: function() {
return [
Meteor.subscribe('customers'),
];
},

data: function() {

var request = Requests.findOne(this.params._id);
if (!request)
return;

var customer = Customers.findOne({'_id': request.customerId});
if (!customer)
return;

return {
sender: Meteor.user(),
recipient: Customers.findOne({_id:Session.get('customerId')})
};
},

emailWelcome: function() {
// Set var in the context so that emailTemplate = 'welcomeEmail' here
this.render('emailPage');
},

emailContract: function() {
// Set var in the context so that emailTemplate = 'contractEmail' here
this.render('emailPage');
}
});

最佳答案

您可以在操作函数中使用 this.getData() 访问数据:

emailWelcome: function() {
var data = this.getData(); // get a reference to the data object
data.emailTemplate = 'welcomeEmail';
this.render('emailPage');
},

emailContract: function() {
var data = this.getData(); // get a reference to the data object
data.emailTemplate = 'contractEmail';

this.render('emailPage');
}
  • 小心不要调用 this.data(),因为这会重新生成数据而不是让您引用已生成的数据对象。
  • 还要注意不要在操作中调用 this.setData(newData),因为这会使旧数据对象失效、启动 react 性重新加载,并且 lead to an infinite loop!

关于javascript - 如何在 Meteor 上使用 IronRouter 在操作中设置数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19732569/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com