编辑:我使用的解决方案是@Kyll的解决方案.
假设我想要返回的服务器端对象"构建起来很复杂",需要来自不同集合的不同属性.
我第一次尝试:
/server/publications.js
Meteor.publish('myCustomDocument', function(){
// suppose here that I need to X.find() different collections
// and create a complex Array of JSON data (which contains different
// attributes from different Collections
return [
{appName: 'aName',
category: 'catName',
anotherField: 'something'},
(...)
];
});
Run Code Online (Sandbox Code Playgroud)
它不起作用,因为它没有返回游标.我想要做的是创建一个从不同集合构建的文档(或文档数组).
我不需要观察该文档的更改.
我为它创建了一个集合:
/collections/myCollection.js
MyCollection = new Meteor.Collection('myCollection');
Run Code Online (Sandbox Code Playgroud)
在客户端,使用铁路由器,我试图做的是:
/lib/router.js
this.route('myPage',{
path: '/myPage',
waitOn: function(){ return Meteor.subscribe('myCollection'); },
data: function(){ return MyCollection.find(); }
});
Run Code Online (Sandbox Code Playgroud)
如何实现向客户端发送非活动数据?