问题描述
我需要一些JavaScript的帮助,我试图在JavaScript的帮助下对XML数据进行排序,并且我成功地完成了排序部分,但是输出返回了一些垃圾对象 [object Object ]
,我不希望它打印出来,所以我需要一些帮助来解决这个问题,以便我得到一个合适的输出。我附上一个活泼的小提琴。所有这些都需要用JavaScript而不是JQUERY来完成。
I need some help with my JavaScript, i am trying to sorting XML data with the help of JavaScript, and i am successful doing the sorting part, but the output is returning some garbage object [object Object]
, which i don't want it to be printed out, so i need some help to get this thing fixed so that i get a proper output. I am attaching a live fiddle. All these needs to be done with JavaScript and not JQUERY.
我不想要 [object Object],[object Object]
将作为输出打印
I don't want [object Object],[object Object]
to be printed as output
bookstore
|
|__book
| |_____title
| |_____author
| |_____year
| |_____price
|
|__book
|
|__book
|
|__book
谢谢
Thank You
推荐答案
这是从其中有来
for (var prop in obj){
li = document.createElement("li");
li.appendChild(document.createTextNode(obj[prop]));
// ...
}
你没有考虑到当 typeof obj [prop]; //object
直到将它附加到树后, createTextNode
将在其参数上调用 ToString ,给出你[object Object]
You're not taking into account when typeof obj[prop]; // "object"
until after appending it to the tree, and createTextNode
will invoke ToString on it's parameters, giving you "[object Object]"
这篇关于Javascript返回[object Object],需要删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!