0
當顯示文檔列表時,可以更清楚地在文檔級別(vs在列表級別)編寫訂閱,以防模板在其他地方重複使用。效率不高還是流星神奇地處理事情?Meteor是否值得批量訂閱?
更確切的說,我可以把文件的邏輯在文檔模板:
Template.itemsList.helpers({
items: function() {
return this.itemsIds.map(function(id) { return { _id: id }; });
},
});
<template name="itemsList">
{{#each items}}{{> item}}{{/each}}
</template>
Template.item.onCreated(function() {
this.subscribe('item', this.data._id);
});
<template name="item">
{{#if Template.subscriptionsReady}}
...
{{/if}}
</template>
或列表級別只訂閱一次,那些文件:
Template.itemsList.onCreated(function() {
this.subscribe('items', this.data.itemsIds);
});
Template.itemsList.helpers({
items: function() {
return Items.find({_id: {$in: this.itemsIds}});
},
});
<template name="itemsList">
{{#if Template.subscriptionsReady}}
{{#each items}}{{> item}}{{/each}}
{{/if}}
</template>
<template name="item">
...
</template>
它看起來像第二種方法它更有效率,因爲只有一個訂閱調用。如果我們在這裏談論標準的http請求,那麼毫無疑問。但是由於Meteor是基於套接字的,並且很好地處理了許多事情,所以我想知道將一些邏輯從文檔移動到列表是值得的。
好的,我想知道'流星'是否會將個人訂閱分組,並與分貝談一次,只是爲了讓他們全部,但我明白這將是一個具有挑戰性的事情。謝謝 – Guig