我有类似下面的XML文件(嵌套集模型):
TEST PREP
-cricket
Forest
-animal
--subtree
---subsubtree and so on.
我想通过仅使用jquery解析来形成一个具有ul li的树。请分享一些想法来做到这一点。正如我们在嵌套集模型中所知,子节点的左值总是在父节点的左右值之间node.I知道如何使用jquery解析xml,但是根本没有想法根据lef和right值循环catgories以形成一个树。谢谢你提前。
输出就像:
#container {
overflow-x: hidden;
}
答案 0 :(得分:1)
一种方法如下:
Updated the hooks directory to have execute permissions
running cordova build android
Running command: C:\Windows\system32\node C:\_Learn\ionic\firstIonicApp\hooks\after_prepare\010_add_platform_class.js C:\_Learn\ionic\firstIonicApp
Error: Hook failed with error code ENOENT: C:\_Learn\ionic\firstIonicApp\hooks\after_prepare\010_add_platform_class.js
at C:\Users\Username\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\hooks\HooksRunner.js:195:23
at _rejected (C:\Users\Username\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:797:24)
at C:\Users\Username\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:823:30
at Promise.when (C:\Users\Username\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:1035:31)
at Promise.promise.promiseDispatch (C:\Users\Username\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:741:41)
at C:\Users\Username\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:557:44
at flush (C:\Users\Username\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:108:17)
at process._tickCallback (node.js:355:11)
at Function.Module.runMain (module.js:503:11)
at startup (node.js:129:16)
答案 1 :(得分:1)
假设你有一个xml存储在一个名为xml的变量和一个id为&#34的div中; someDiv"
var xmlDoc = $.parseXML(xml);
var result = "<ul>";
$(xmlDoc).find("nested_category").each(function()
{
result += "<li>"+ "category_id : " + $(this).find("category_id").text() +"</br>";
result += "name : " + $(this).find("name").text() +"</br>";
result += "alias : " + $(this).find("alias").text() +"</br>";
result += "lft : " + $(this).find("lft").text() +"</br>";
result += "rgt : " + $(this).find("rgt").text();
result += "</li>";
});
result += "</ul>";
$("#someDiv").append(result);
将生成
您可以查看更多的$ .parseXML() https://api.jquery.com/jQuery.parseXML/
希望它有所帮助, 丹