ฉันกำลังสร้างแผนผังโดยใช้ปลั๊กอิน jsTree ด้วย ASP.NET MVC 4 นี่คือโค้ดของฉันก่อนที่จะอธิบายอย่างละเอียด:
HTML:
<div id="MainTree"></div>
<div onclick="$load();">Load Tree</div>
จาวาสคริปต์:
$load = function(){
$('#MainTree').jstree({
"json_data": {
"ajax": {
"url": "/Home/GetTreeData",
"type": "POST",
"dataType": "json",
"contentType": "application/json charset=utf-8"
}
},
"themes": {
"theme": "default",
"dots": false,
"icons": true,
"url": "/content/themes/default/style.css"
},
"plugins": ["themes", "json_data", "dnd", "contextmenu", "ui", "crrm"]
});
}
ตัวควบคุม:
[HttpPost]
public JsonResult GetTreeData()
{
JsTreeModel rootNode = new JsTreeModel(); // Breakpoint here, never triggered
rootNode.attr = new JsTreeAttribute();
rootNode.data = "Root";
string rootPath = "Test";
rootNode.attr.id = rootPath;
JsTreeModel t1 = new JsTreeModel();
t1.attr.id = "1";
JsTreeModel t2 = new JsTreeModel();
t2.attr.id = "2";
JsTreeModel t3 = new JsTreeModel();
t3.attr.id = "3";
rootNode.children.Add(t1);
rootNode.children.Add(t2);
rootNode.children.Add(t3);
return Json(rootNode);
}
เมื่อฉันคลิกปุ่ม "โหลดทรี" $load()
จะถูกทริกเกอร์และใน Firefox ดีบัก มันจะทำงานโดยไม่มีข้อผิดพลาดเกิดขึ้น ต้นไม้ <div>
เปลี่ยนแปลงจาก:
<div id="MainTree"></div>
to
<div role="tree" class="jstree jstree-1 jstree-default jstree-default-responsive jstree-leaf" id="MainTree">
<ul class="jstree-container-ul"></ul>
</div>
ฉันวางเบรกพอยต์ไว้ในคอนโทรลเลอร์ตามที่ระบุไว้ในความคิดเห็น ซึ่งไม่เคยถูกกระตุ้น กล่าวคือ ดูเหมือนว่าจะไม่มีการเรียกไปยังผู้ควบคุมเลย HomeController.cs
ของฉันไม่มีข้อผิดพลาดทางไวยากรณ์
ฉันพลาดอะไรบางอย่างที่นี่หรือเปล่า?