【发布时间】:2016-02-16 14:46:29
【问题描述】:
我正在使用 oboe.js,并且我想从节点“sections”中检索数据,并将祖先 profile_namespace 和 owner_name 映射到从 section 节点检索的数据(请参阅下面的 json 文件提取)。
JSON 文件提取 (myjson.json):
{
"data": [{
"profile_namespace": "DS",
"tutorial": {
"owner_name": "Dominic",
"picture_url": "/picture.jpg",
"title": "The code",
"url": "/Dominic/thecode/",
"sections": [{
"episode_url": "/tutorial/intro/symphony-of-war/",
"artist": "MasterOrchestra",
"title": "Symphony of War"
}, {
"episode_url": "/tutorial/mainshow/musicproductiontip1/",
"artist": "DStone",
"title": "Music production tip 1"
}, {
"episode_url": "/tutorial/outrothe/nextshow/",
"artist": "MasterOrchestra",
"title": "Next show"
}]
}
}]
}
现在我只能从节点“部分”中检索数据,但我在文档中看到 .node 返回可链接方法,并且可以使用“祖先”的概念从父节点中检索数据。
谁能解释我如何使用这个方法(见下面我的代码)?
代码
var oboe = require('oboe');
var fs = require('fs');
var SetList = require('fs');
var setList = [];
var showInfo = require('fs');
oboe(fs.createReadStream('/myjson.json'))
.node({
'sections': function(node) {
setList.push(node);
showInfo = fs.createWriteStream('/showInfo.json');
showInfo.write(JSON.stringify(setList));
}
});
感谢您的帮助!
多米尼克
【问题讨论】:
标签: javascript node.js oboe.js