簡體   English   中英

如何在RacerJs DerbyJs中將項目添加到集合中?

[英]How to add an item to a collection in RacerJs DerbyJs?

我想使用RacerJs / DerbyJs將一個項目添加到集合中,但是它不起作用。 我一定是真的忽略了什么...

我嘗試了什么

model.set('news', [
    { text: "something" }
]);

確實設置了一個新聞項目。 但是,當我再次執行此操作時,它只會覆蓋現有項,而不會添加新項。 怎么做?

model.push('news', {text:"someText"})也因“對象不是數組”而失敗。

基本上,我只想要“發布更新並在'wall'應用程序上顯示”的最基本版本,而沒有任何空間或使用Array。 僅一個集合,僅此而已。

.push()變體的Stacktrace:

Wed May 22 2013 09:35:24 GMT+0200 (W. Europe Daylight Time) (23168) d7564d2d-f23
8-4ce0-a0a2-6e376e9b5cb1 ? ver: 0 - push 'news', { text: 'adsf' }

C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\lib\
Memory.js:185
    throw new TypeError(arr + ' is not an Array');
          ^
TypeError: [object Object] is not an Array
    at Object.arrayLookupSet [as _arrayLookupSet] (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\lib\Memory.js:185:11)
    at Object.applyArrayMethod [as _applyArrayMethod] (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\lib\Memory.js:145:18)
    at Object.push (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\lib\Memory.js:118:15)
    at applyTxn (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\lib\transaction.js:114:32)
    at Object.exports.applyTxnToDoc (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\lib\transaction.js:126:3)
    at Function.QueryInterface.publish (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\lib\adapters\pubsub-memory\channel-interface-query.js:25:24)
    at PubSub.publish (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\lib\pubSub\PubSub.js:63:10)
    at Store.module.exports.proto.publish (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\lib\pubSub\pubSub.Store.js:174:20)
    at publish (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\lib\txns\txns.Store.js:230:15)
    at next (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\lib\middleware.js:7:26)
    at module.exports.events.middleware.txn (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\lib\txns\txns.Store.js:220:11)
    at Store._sendToDb.lockingDone (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\lib\Store.js:294:12)
    at mergeAll.setupRoutes (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\lib\adapters\db-memory\index.js:70:13)
    at DbMemory.mergeAll.get (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\lib\adapters\db-memory\index.js:44:5)
    at mergeAll.setupRoutes (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\lib\adapters\db-memory\index.js:62:16)
    at DbMemory.mergeAll.get (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\lib\adapters\db-memory\index.js:44:5)
    at mergeAll.setupRoutes (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\lib\adapters\db-memory\index.js:60:14)
    at next (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\lib\Store.js:321:15)
    at Store._sendToDb (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\lib\Store.js:324:10)
    at writeToDb (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\lib\txns\txns.Store.js:216:15)
    at next (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\lib\middleware.js:7:26)
    at serialEmitPrep (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\lib\txns\txns.Store.js:125:9)
    at next (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\lib\middleware.js:7:26)
    at incrVer (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\lib\modes\lww.js:18:12)
    at next (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\lib\middleware.js:7:26)
    at Object.module.exports.events.init.store.eachContext.context.guardWrite (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\lib\accessControl\accessControl.Store.js:54:51)
    at accessController (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\lib\txns\txns.Store.js:103:17)
    at next (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\lib\middleware.js:7:26)
    at Object.run (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\lib\middleware.js:10:12)
    at Socket.module.exports.events.socket (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\lib\txns\txns.Store.js:267:26)
    at Socket.racer.log.sockets.sockets.on.socket.on (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\lib\log.server.js:150:20)
    at Socket.EventEmitter.emit [as $emit] (events.js:91:17)
    at SocketNamespace.handlePacket (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\node_modules\socket.io\lib\namespace.js:335:22)
    at Manager.onClientMessage (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\node_modules\socket.io\lib\manager.js:488:38)
    at WebSocket.Transport.onMessage (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\node_modules\socket.io\lib\transport.js:387:20)
    at Parser. (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\node_modules\socket.io\lib\transports\websocket\hybi-16.js:39:10)
    at Parser.EventEmitter.emit (events.js:88:17)
    at opcodeHandlers.1.finish (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\node_modules\socket.io\lib\transports\websocket\hybi-16.js:288:16)
    at Parser.opcodeHandlers.1.expectData [as expectHandler] (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\node_modules\socket.io\lib\transports\websocket\hybi-16.js:299:15)
    at Parser.add (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\node_modules\socket.io\lib\transports\websocket\hybi-16.js:466:24)
    at Parser.expect (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\node_modules\socket.io\lib\transports\websocket\hybi-16.js:499:10)
    at Parser.opcodeHandlers.1.expectData (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\node_modules\socket.io\lib\transports\websocket\hybi-16.js:298:18)
    at Parser.add (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\node_modules\socket.io\lib\transports\websocket\hybi-16.js:466:24)
    at Parser.expect (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\node_modules\socket.io\lib\transports\websocket\hybi-16.js:499:10)
    at opcodeHandlers.1.expectData (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\node_modules\socket.io\lib\transports\websocket\hybi-16.js:296:16)
    at opcodeHandlers.1 (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\node_modules\socket.io\lib\transports\websocket\hybi-16.js:313:9)
    at Parser.processPacket (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\node_modules\socket.io\lib\transports\websocket\hybi-16.js:533:8)
    at Parser.add (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\node_modules\socket.io\lib\transports\websocket\hybi-16.js:466:24)
    at Socket.WebSocket.onSocketConnect (C:\xampp\htdocs\Derbyjs\KnowEdge\app1\node_modules\derby\node_modules\racer\node_modules\socket.io\lib\transports\websocket\hybi-16.js:141:17)
    at Socket.EventEmitter.emit (events.js:88:17)
    at TCP.onread (net.js:396:14)

如果您試圖將文檔添加到集合中,也可以調用model.add

model.add('news', {
  text: "Something" 
})

它將為新聞集添加一個新文檔並為您生成ID。 可以在http://derbyjs.com/#getters_and_setters下找到更多文檔

要在集合中創建項目,您可以使用包含文檔ID的顯式指定路徑調用model.set ,例如:

model.set('news.' + model.id(), {
  text: "something"
})

model.id方法將在每次調用時生成唯一的ID。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM