2015-03-31 66 views
0

試圖在我的asp.net mvc 5項目中使用jsTree。但無法弄清楚它爲什麼不起作用?這裏也是小提琴鏈接。 https://dotnetfiddle.net/24h7NmjsTree的jquery插件不工作在mvc 5?

控制器: -

public ActionResult ShowTree() 
{ 
      return View(); 
} 

查看: -

@{ 
    ViewBag.Title = "ShowTree"; 
} 
<link href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.1.0/themes/default/style.min.css" rel="stylesheet" /> 

<script> 
$(function() { 
    $("#divTree").jstree(); 
}); 

</script> 
<h2>ShowTerms</h2> 

<div id="divTree"> 
    <ul> 
     <li> 
      Root node 11 
      <ul> 
       <li id="child_node_1">Child node 1</li> 
       <li>Child node 2</li> 
      </ul> 
     </li> 
     <li>Root node 2</li> 
    </ul> 
</div> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.1.0/jstree.min.js"></script> 
<script src="~/Scripts/app.js"></script> 

回答

0

您正在嘗試使用$ jQuery是可用之前。將<script>塊向下移動,如下所示:

@{ 
    ViewBag.Title = "ShowTree"; 
} 
<link href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.1.0/themes/default/style.min.css" rel="stylesheet" /> 

<h2>ShowTerms</h2> 

<div id="divTree"> 
    <ul> 
     <li> 
      Root node 11 
      <ul> 
       <li id="child_node_1">Child node 1</li> 
       <li>Child node 2</li> 
      </ul> 
     </li> 
     <li>Root node 2</li> 
    </ul> 
</div> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.1.0/jstree.min.js"></script> 
<script src="~/Scripts/app.js"></script> 
<script> 
$(function() { 
    $("#divTree").jstree(); 
}); 
</script>