KendoUI TreeView绑定问题

时间:2014-04-04 07:28:15

标签: kendo-ui

我正面临一个问题,下面的代码第一次绑定树,但第二次没有工作绑定树:(但当我再次请求第三次绑定时。

甚至意味着请求工作。

请帮帮我

提前致谢

Mobeen

//我的示例数据

{“d”:[{“_ type”:“ManageUPPRM.UserDocumentDTO”,“DocumentID”:1804105651,“DocumentName”:“Google Talk”,“hasChildren”:true},{“ _type “:” ManageUPPRM.UserDocumentDTO”, “DocumentID”:15854591701, “DocumentName”: “的desktop.ini”, “hasChildren”:假},{ “__类型”: “ManageUPPRM.UserDocumentDTO”, “DocumentID”:15861429553 “DocumentName”: “Jellyfish.jpg”, “hasChildren”:假}]}

//代码

var datasource = new kendo.data.HierarchicalDataSource({
                transport: {
                    read: function (options) {
                        var id = options.data.DocumentID;

                        if (typeof id == "undefined") {
                            id = "0"
                        }

                        $.ajax({
                            type: "POST",
                            url: "../ManageUPWebService.asmx/GetAllDocuments",
                            dataType: "json",
                            contentType: "application/json; charset=utf-8",
                            data: "{DocumentID:'" + id + "'}",
                            success: function (result) {
                                // notify the data source that the request succeeded
                                options.success(result.d);
                            },
                            error: function (result) {
                                // notify the data source that the request failed
                                options.error(result.d);
                            }
                        });
                    }
                },
                schema: {
               model: {
                        id: "DocumentID",
                        text: "DocumentName",
                        hasChildren: "hasChildren"
                    }
                }
            });

            $("#treeview").kendoTreeView({

                checkboxes: {
                    checkChildren: true,
                    template: "<input type='checkbox' name='#=item.id#' data-text='#=item.DocumentName#' value='true' />"
                },

                loadOnDemand: true,
                dataSource: datasource,
                dataTextField: "DocumentName"
            });

1 个答案:

答案 0 :(得分:2)

试试这个, 添加一个带有一些id的div作为treeview的父div

<div id="parent"><div id="treeview"></div></div>

并且在绑定剑道树之前

$("#treeview").remove();
$("<div id=\"treeview\" />").appendTo("#parent").kendoTreeView({
            checkboxes: {
                checkChildren: true,
                template: "<input type='checkbox' name='#=item.id#' data-text='#=item.DocumentName#' value='true' />"
            },

            loadOnDemand: true,
            dataSource: datasource,
            dataTextField: "DocumentName"
        });