我在服務器控制檯發現這個錯誤:Meteor.publish()扔在延遲迴調異常
Exception in defer callback: TypeError: undefined is not a function at packages/ddp/livedata_server.js:1054:1 at Array.forEach (native) at Function..each..forEach (packages/underscore/underscore.js:105:1) at [object Object]._.extend._callStopCallbacks (packages/ddp/livedata_server.js:1053:1) at [object Object]._.extend._deactivate (packages/ddp/livedata_server.js:1043:1) at packages/ddp/livedata_server.js:803:1 at Function..each..forEach (packages/underscore/underscore.js:113:1) at [object Object]._.extend._deactivateAllSubscriptions (packages/ddp/livedata_server.js:802:1) at packages/ddp/livedata_server.js:444:1 at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
在這裏,我使用的代碼:
/* Source: http://phucnguyen.info/blog/how-to-publish-to-a-client-only-collection-in-meteor/ */
var subs = {};
Meteor.publish(
// THROW AN 'EXCEPTION IN DERFER CALLBACK: ...'
'helperPublication',
function() {
var subscription = this;
subs[subscription._session.id] = subscription;
Datasets.find().map(function (dataset) {
subscription.added(
'subdatasets',
dataset._id,
{
name: dataset.name,
data: [], // To avoid "Uncaught TypeError: Cannot read property 'length' of undefined" error on load
peaks: [] // Idem
}
)
});
subscription.onStop();
subscription.ready()
});
你可以找到整個應用程序在以下meteorpad:http://meteorpad.com/pad/6NDneym2qEW7pF9JM/ClearChrom
我認爲有很多事情你錯了。你用這個代碼試圖達到什麼目的? – Kriegslustig
對於性能問題,我使用2個獨立的數據庫。一個稱爲數據集,由客戶端(受限訪問)和服務器共享。另一個是僅限客戶端的數據庫:它存儲數據集文檔的克隆**但是**數據是數據的短子集(按需加載)。 通過上面的代碼,我想將Datasets文檔複製到僅客戶端的數據庫中。而且,可選地,我希望爲每個連接的客戶端做到這一點(但坦率地說,我並不真的需要_也不希望這樣做,但我不知道如何更改Phuc Nguyen代碼的那部分內容......)。 這是否使它更清晰? –