首页新闻找找看学习计划

Kendo 树形复选框如何读取服务接口数据源???

0
悬赏园豆:30 [已关闭问题] 关闭于 2016-06-30 15:50

百度上的,基本都是绑定的死数据,如何用接口去读取?

代码如下:

 1 <!DOCTYPE html>
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
 5     <title>复选框</title>
 6     <!--引用-->
 7     <link href="../js/style/kendo.rtl.min.css" rel="stylesheet" />
 8     <link href="../js/style/kendo.common.min.css" rel="stylesheet" />
 9     <link href="../js/style/kendo.dataviz.min.css" rel="stylesheet" />
10     <link href="../js/style/kendo.dataviz.default.min.css" rel="stylesheet" />
11     <link href="../js/style/kendo.default.min.css" rel="stylesheet" />
12     <script src="../js/kendo/jquery.min.js"></script>
13     <script src="../js/kendo/angular.min.js"></script>
14     <script src="../js/kendo/kendo.all.min.js"></script>
15 </head>
16 <body>
17     <div class="demo-section k-header">
18         <div class="box-col">
19             <h4>Check nodes</h4>
20             <div id="treeview"></div>
21         </div>
22         <div class="box-col">
23             <h4>Status</h4>
24             <p id="result">No nodes checked.</p>
25         </div>
26     </div>
27     <script type="text/javascript">
28         var DataUrl = "";//服务接口
29 
30         $(document).ready(function () {
31             var dataSource = new kendo.data.DataSource({
32                 transport: {
33                     read: {
34                         url: DataUrl,
35                         type: "POST",
36                         dataType: "json", //json格式
37                         contentType: "application/json",
38                     }
39                 },
40                 schema: {
41                     model: {
42                         children: "SonList",
43                         id: "id"
44                     }
45                 }
46             });
47             $("#treeview").kendoTreeView({
48                 checkboxes: {
49                     checkChildren: true
50                 },
51                 check: onCheck,
52                 dataTextField: "Name",
53                 dataValueField: "Id",
54                 dataSource:dataSource
55             })
56         })
57  function checkedNodeIds(nodes, checkedNodes) {
58             for (var i = 0; i < nodes.length; i++) {
59                 if (nodes[i].checked) {
60                     checkedNodes.push(nodes[i].id);
61                 }
62 
63                 if (nodes[i].hasChildren) {
64                     checkedNodeIds(nodes[i].children.view(), checkedNodes);
65                 }
66             }
67         }
68 
69         function onCheck() {
70             var checkedNodes = [],
71                 treeView = $("#treeview").data("kendoTreeView"),
72                 message;
73 
74             checkedNodeIds(treeView.dataSource.view(), checkedNodes);
75 
76             if (checkedNodes.length > 0) {
77                 message = "IDs of checked nodes: " + checkedNodes.join(",");
78             } else {
79                 message = "No nodes checked.";
80             }
81 
82             $("#result").html(message);
83         }
84     </script>
85 </body>
86 </html>
View Code
H-SMouses的主页 H-SMouses | 初学一级 | 园豆:14
提问于:2016-06-30 10:28
< >
分享
所有回答(1)
0

楼主碰到的这个问题是怎么解决的,能帮我一下吗?

琴声 | 园豆:147 (初学一级) | 2017-06-01 15:59
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册