我正在尝试从"OutputArray“创建下面的"InputObject”。我已经创建了一个函数getdata()来转换这两个对象。当我将这些对象以chrome格式写入控制台时,显示方式略有不同,屏幕截图如下。
OuputObect: (这是我想要的输出)
{
"id" : "1",
"name" : "Name the color",
"q" : "what is the color white in HTML",
"a" : "255 255 255",
"video" : "http://aws.asdfsadf.com/something.mkv",
"images" : {
"title" : "White Image",
"url" : "http://aws.asdfsdf.com/image.jpg"
}
},
{
"id" : "2",
"name" : "Name the color",
"q" : "what is the color black in HTML",
"a" : "0 0 0",
"video" : "http://aws.asdfsadf.com/something.mkv",
"images" : {
"title" : "White Image",
"url" : "http://aws.asdfsdf.com/image.jpg"
}
}OutputObject应以铬显示如下: console.log(OutputObject)

相反,是这样的: console.log(getdata(InputObject))

InputObject: (FireDB是这样表示数据的)
{
"1" : {
"name" : "Name the color",
"q" : "what is the color white in HTML",
"a" : "255 255 255",
"video" : "http://aws.asdfsadf.com/something.mkv",
"images" : {
"title" : "White Image",
"url" : "http://aws.asdfsdf.com/image.jpg"
}
},
"2" : {
"name" : "Name the color",
"q" : "what is the color black in HTML",
"a" : "0 0 0",
"video" : "http://aws.asdfsadf.com/something.mkv",
"images" : {
"title" : "White Image",
"url" : "http://aws.asdfsdf.com/image.jpg"
}
}
}getdata()函数.
function getdata(data){
var array = [];
for (var key in data) {
var arrayObject = {};
// skip loop if the property is from prototype
if (!data.hasOwnProperty(key)) continue;
var obj = jsondata.questions[key];
for (var prop in obj) {
// skip loop if the property is from prototype
if(!obj.hasOwnProperty(prop)) continue;
arrayObject[prop] = obj[prop];
}
arrayObject["id"] = key;
array.push(arrayObject)
}
return array;
}发布于 2016-10-02 02:52:34
事实证明,这两个数组是相等的,他们只是显示在不同的铬。
我的问题是我打电话给ko.observableArray(OutputObject)
(加上方括号)
而不是:
ko.observableArray(getdata(OutputObject));
https://stackoverflow.com/questions/39813255
复制相似问题