我有一个模板,其中填充了所有转移
Template.listTransfers.helpers({
transfers: function () {
var thisId = Meteor.userId();
return Transfers.find({userId: thisId}, {sort: {timeCreated: -1}});
},
});
我在模板中还有一个click事件,需要过滤出有发票的转账 return Transfers.find({userId: thisId, 'invoice' : {$exists : 1}}, {sort: {timeCreated: -1}});
我有这样的模板拉动转移
{{#each transfers}}
{{> transferItem}}
{{/each}}
有没有办法在该语句中执行此操作,还是需要创建一条单独的路由?
您可以在模板实例上使用ReactiveVar,如下所示:
Template.listTransfers.created({
// Initialize a reactive variable on the template instance
this.showInvoices = new ReactiveVar(true);
});
Template.listTransfers.helpers({
transfers: function () {
var thisId = Meteor.userId();
var showInvoices = Template.instance().showInvoices;
if (showInvoices.get()) {
return Transfers.find({userId: thisId}, {sort: {timeCreated: -1}});
} else {
return Transfers.find({userId: thisId, 'invoice' : {$exists : 1}}, {sort: {timeCreated: -1}});
}
},
});
Template.listTransfers.events({
"click button.hide-invoices": function () {
var showInvoices = Template.instance().showInvoices;
// Toggle the showInvoices var
showInvoices.set(! showInvoices.get());
}
})
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句