我在 Kimonolabs 中有 Json 输出文件,看起来像这样
{
"name": "text",
"results": {
"collection1": [
{
"title": {
"href": "link",
"text": "text"
},
"description": "text",
"author": "text",
"index": 1,
"url": "link"
},etc.
}]}}
我想向 collection1 数组中的变量添加一个变量“类别”,并为每个数组项设置该类别的值“食物”。但是整天都在努力让它工作。有什么建议么?
我尝试的是:
function transform (data){
//create shortcut for collection variable
var collection = data.results.collection1;
//function to add category
function addcat(line){
line[category] ='food';
return row;
}
//loop through variables;
for (var i=0; i < collection.length; i++){
[collection] = [collection].map(addcat);
return data;
}