未捕获的TypeError:无法读取属性'替换'与KendoTreeView`未定义的

时间:2014-06-27 10:44:15

标签: kendo-ui kendo-treeview

下面是我的KendoUI树视图,我使用模板在每个节点上显示编辑链接,但我收到此错误:“未捕获TypeError:无法读取属性'替换'未定义”

 @section scripts{
        <script src="~/scripts/kendo.all.min.js"></script>

        <script type="text/javascript">

          var  territory = new kendo.data.HierarchicalDataSource({
                transport: {
                    read: {
                        type:'POST',
                        url: rootURL + "Territory/AllTerritories",
                        dataType: "json"
                    }
                },
                schema: {
                    model: {
                        id: "ID",
                        hasChildren: "HasChildren",
                        children: territory

                    }
                }
            });

            $("#treeview").kendoTreeView({
                dataSource: territory,
                dataTextField: "Name",
                dataValueField: "ID",
                template: kendo.template($("#treeview-template").html())
            });

        </script>



    }

    <script id="treeview-template" type="text/kendo-ui-template">
        #
        <a class='show-link' href='\#'><image src="/Content/images/select2.png"></a> #
    </script>
    <style scoped>
        #territoryTree {
            text-align: center;
        }
        #treeview .k-sprite {
            background-image: url("../content/default/coloricons-sprite.png");

        }
        .rootfolder {
            background-position: 0 0;
        }
        .demo-section {
            display: inline-block;
            vertical-align: text-bottom;
            min-width: 320px;
            min-height: 300px;
            text-align: left;
            margin: 0 2em;
        }
    </style>

任何解决方案?请帮忙

1 个答案:

答案 0 :(得分:4)

当您说

时,jquery无法找到ID为#treeview-template的元素
kendo.template($("#treeview-template").html())

然后首先它将尝试找到具有Id #treeview-template的html元素,然后它将向前移动。通过在控制台中编写$("#treeview-template").html()来尝试F12和控制台,看看它是否可以找到元素