2017-10-18 74 views
1

Node.js的-Node.js的,没有浏览器,枪0.8.8无法创建与阵列的对象作为一个属性

创建对象

const body = { 
    a: { 
    must: [ 
     { name: 'first', size: 1 } 
    ] 
    } 
}; 
gun.get('watcher/f0de26c0-a29f-11e7-8661-154b982951a4').put(body); 

接收错误

Invalid value at 'a.must'! 

服务器

const Hapi = require('hapi'); 
const Gun = require('gun'); 

const server = new Hapi.Server; 
server.connection({ port: 8080 }); 
server.connections.forEach(c => Gun({ web: c.listener, file: 'data.json' })); 
server.start(); 

回答

1

枪不跟踪数组。 根据您希望自己跟踪元素还是整个数组,您有几种选择来表示数组。

1)作出这样的行为有点像阵列

{ 
    0: 1, 
    1: 134, 
    2: "abc" 
} 

2)字符串化阵列和存储的对象是作为一个propergy

{ val : '[1,134,"abc"]' } 
相关问题