2013-08-07 281 views
0

我試圖讓複選框選項使用KendoTree視圖。我複製了完全相同的代碼並補充說:未捕獲TypeError:無法讀取未定義的屬性'dataSource'

<link href="kendo/kendo.common.min.css" rel="stylesheet" /> 
<link href="kendo/kendo.default.min.css" rel="stylesheet" /> 
<script src="kendo/jquery.min.js" /> 
<script src="kendo/kendo.all.min.js" /> 

<script> 
    $("#treeview").kendoTreeView({ 
     checkboxes: { 
      checkChildren: true 
     }, 

     dataSource: [{ 
      id: 1, text: "My Documents", expanded: true, spriteCssClass: "rootfolder", items: [ 
       { 
        id: 2, text: "Kendo UI Project", expanded: true, spriteCssClass: "folder", items: [ 
         { id: 3, text: "about.html", spriteCssClass: "html" }, 
         { id: 4, text: "index.html", spriteCssClass: "html" }, 
         { id: 5, text: "logo.png", spriteCssClass: "image" } 
        ] 
       }, 
       { 
        id: 6, text: "New Web Site", expanded: true, spriteCssClass: "folder", items: [ 
         { id: 7, text: "mockup.jpg", spriteCssClass: "image" }, 
         { id: 8, text: "Research.pdf", spriteCssClass: "pdf" }, 
        ] 
       }, 
       { 
        id: 9, text: "Reports", expanded: true, spriteCssClass: "folder", items: [ 
         { id: 10, text: "February.pdf", spriteCssClass: "pdf" }, 
         { id: 11, text: "March.pdf", spriteCssClass: "pdf" }, 
         { id: 12, text: "April.pdf", spriteCssClass: "pdf" } 
        ] 
       } 
      ] 
     }] 
    }); 

    // function that gathers IDs of checked nodes 
    function checkedNodeIds(nodes, checkedNodes) { 
     for (var i = 0; i < nodes.length; i++) { 
      if (nodes[i].checked) { 
       checkedNodes.push(nodes[i].id); 
      } 

      if (nodes[i].hasChildren) { 
       checkedNodeIds(nodes[i].children.view(), checkedNodes); 
      } 
     } 
    } 

    // show checked node IDs on datasource change 
    $("#treeview").data("kendoTreeView").dataSource.bind("change", function() { 
     var checkedNodes = [], 
      treeView = $("#treeview").data("kendoTreeView"), 
      message; 

     checkedNodeIds(treeView.dataSource.view(), checkedNodes); 

     if (checkedNodes.length > 0) { 
      message = "IDs of checked nodes: " + checkedNodes.join(","); 
     } else { 
      message = "No nodes checked."; 
     } 

     $("#result").html(message); 
    }); 
</script> 

它給我 -

遺漏的類型錯誤:未定義無法讀取屬性「數據源」。

任何幫助將是偉大的。

謝謝。 鮮于

+0

任何運氣 - 您的問題是否解決? – Vojtiik

回答

0

Nope-我無法得到它的工作..我使用FlatUI主題,所以它可能是與主題有關的問題。

 Uncaught TypeError: Cannot read property 'dataSource' of undefined index2.html:211 
     (anonymous function) index2.html:211 
     i.extend.trigger kendo.all.min.js:9 
     nt.extend._process kendo.all.min.js:11 
     nt.extend._change kendo.all.min.js:11 
     b.isFunction.i jquery.min.js:3 
     i.extend.trigger kendo.all.min.js:9 
     (anonymous function) kendo.all.min.js:11 
     i.extend.trigger kendo.all.min.js:9 
     (anonymous function) kendo.all.min.js:11 
     i.extend.trigger kendo.all.min.js:9 
     nt.extend._process kendo.all.min.js:11 
     nt.extend._change kendo.all.min.js:11 
     b.isFunction.i jquery.min.js:3 
     i.extend.trigger kendo.all.min.js:9 
     (anonymous function) kendo.all.min.js:11 
     i.extend.trigger kendo.all.min.js:9 
     (anonymous function) kendo.all.min.js:11 
     i.extend.trigger kendo.all.min.js:9 
     nt.extend._process kendo.all.min.js:11 
     nt.extend._change kendo.all.min.js:11 
     b.isFunction.i jquery.min.js:3 
     i.extend.trigger kendo.all.min.js:9 
     (anonymous function) kendo.all.min.js:11 
     i.extend.trigger kendo.all.min.js:9 
     nt.extend.set kendo.all.min.js:11 
     Rt.extend.set kendo.all.min.js:11 
     v.extend._checkboxChange kendo.all.min.js:24 
     b.isFunction.i jquery.min.js:3 
     b.event.dispatch jquery.min.js:3 
     v.handle 
+0

我得到它的工作 - 這是主題問題, – SKJQuery

+1

關於你的解決方案是什麼進一步的指導?我想我有同樣的問題 – ledragon

相關問題