我的答复是:
[{
"id": 425055,
"title": "Foo"
}, {
"id": 425038,
"title": "Bar"
}, {
"id": 425015,
"title": "Narf"
}]我使用oboe.js创建一个高地流:
const cruiseNidStream = _((push, next) => {
oboe({
url: 'http://fake.com/bar/overview,
method: 'GET',
headers: {
'X-AUTH': 'some token',
},
}).node('.*', (overview) => {
// I expect here to get an object having and id, title property
push(null, overview.id);
}).done((overview) => {
push(null, _.nil);
}).fail((reason) => {
console.error(reason);
push(null, _.nil);
});
});我的问题是,我不知道如何使用节点来匹配该数组的每个元素。目前,我在当前设置中获得的项都是所有对象和属性:
425055
Foo
{ id: 227709, title: 'Foo' }如果响应具有如下属性:
{
'overview': [],
}我本可以用.overview.*的。
发布于 2016-12-14 19:09:57
双簧管有两种方式来匹配数据,通过路径和鸭子类型.
打鸭
oboe('/data.json')
.node('{id title}', function(x) {
console.log('from duck-typing', x)
})旁路
oboe('/data.json')
.node('!.*', function(x) {
console.log('from path matching', x)
})
//or also valid
.node('!.[*]', function(x) {
console.log('from path matching', x)
})在path示例中,请注意!字符。这是指树的根节点,这种模式只会把你的三个对象,而不是自己的任何一个属性嵌套得更深。
发布于 2016-12-13 19:29:14
Oboe.js支持鸭子类型:
.node('{id title}', (overview) => {
}请注意,我的json是平的,所以这是可行的。对于嵌套的json,结果可能会有所不同。
https://stackoverflow.com/questions/41129070
复制相似问题