单击如何仅显示具有任务的集合条目:'Test'?
On click how to only show collection entries with task: 'Test'?
下面的代码仅加载任务具有条目“Test”的数据。
Meteor.publish 'activities', ->
Activities.find(task: 'Test')
当代码为:
时,单击按钮时如何实现相同的效果
Meteor.publish 'activities', ->
Activities.find()
到目前为止,这是我的代码:
客户:
Template.dashboard.events({
'click .ButtonDemo': function (e) {
e.preventDefault();
console.log("Successful click");
activities: Activities.find({task: 'Test'}).fetch()
}
});
路由器:
@route "dashboard",
path: "/dashboard"
waitOn: ->
[
subs.subscribe 'activities'
]
data: ->
activities: Activities.find({},{sort: {createdAt: -1}}).fetch()
将(核心)reactive-var package 添加到您的项目中:meteor add reactive-var
。
然后:
在服务器上,更改您的发布以采用参数:
Meteor.publish('activities', (filter = {}) => { return Activities.find(filter); });
在客户端,声明反应变量:
const filter = new ReactiveVar({})
更改您的订阅以将该变量作为参数:
Meteor.subscribe('activities', filter);
并在点击时设置该变量:
Template.dashboard.events({
'click .ButtonDemo': () => {
console.log("Successful click");
filter.set({task: 'Test'});
return false;
}
});
下面的代码仅加载任务具有条目“Test”的数据。
Meteor.publish 'activities', ->
Activities.find(task: 'Test')
当代码为:
时,单击按钮时如何实现相同的效果Meteor.publish 'activities', ->
Activities.find()
到目前为止,这是我的代码:
客户:
Template.dashboard.events({
'click .ButtonDemo': function (e) {
e.preventDefault();
console.log("Successful click");
activities: Activities.find({task: 'Test'}).fetch()
}
});
路由器:
@route "dashboard",
path: "/dashboard"
waitOn: ->
[
subs.subscribe 'activities'
]
data: ->
activities: Activities.find({},{sort: {createdAt: -1}}).fetch()
将(核心)reactive-var package 添加到您的项目中:meteor add reactive-var
。
然后:
在服务器上,更改您的发布以采用参数:
Meteor.publish('activities', (filter = {}) => { return Activities.find(filter); });
在客户端,声明反应变量:
const filter = new ReactiveVar({})
更改您的订阅以将该变量作为参数:
Meteor.subscribe('activities', filter);
并在点击时设置该变量:
Template.dashboard.events({
'click .ButtonDemo': () => {
console.log("Successful click");
filter.set({task: 'Test'});
return false;
}
});