【问题标题】:Uncaught TypeError: Cannot read property 'replace' of undefined未捕获的类型错误:无法读取未定义的属性“替换”
【发布时间】:2014-06-09 03:47:14
【问题描述】:

我是使用 Kendo Grid 和 Kendo UI 的新手。我的问题是如何解决这个错误

Uncaught TypeError: Cannot read property 'replace' of undefined 

这是我在 KendoGrid 上的代码

$("#Grid").kendoGrid({
            scrollable: false,
            sortable: true,
            pageable: {
                refresh: true,
                pageSizes: true
            },
            dataSource: {
                transport: {
                    read: {
                        url: '/Info/InfoList?search=' + search,
                        dataType: "json",
                        type: "POST"
                    }

                },
                pageSize: 10
            },
            rowTemplate: kendo.template($("#rowTemplate").html().replace('k-alt', '')),
            altRowTemplate: kendo.template($("#rowTemplate").html())
        });

导致错误的行

rowTemplate: kendo.template($("#rowTemplate").html().replace('k-alt', '')),

rowTemplate 的 HTML

   <script id="rowTemplate" type="text/x-kendo-tmpl">   
        <tr class='k-alt'>
            <td>
                ${ FirstName } ${ LastName }
            </td>
        </tr>
            </script>

谢谢:)

【问题讨论】:

  • 因为$("#rowTemplate").html() 返回未定义
  • 你的页面中是否有id为rowTemplate的元素
  • @ArunPJohny 是的。等我更新我的问题
  • 你能在$("#Grid").kendoGrid({..});之前做alert($("#rowTemplate").length)
  • @ArunPJohny 先生,它会提醒0 接下来我该怎么做?还检查了 id 的命名,但它们都是唯一的

标签: c# jquery asp.net-mvc gridview kendo-ui


【解决方案1】:

我认为 jQuery 找不到该元素。

首先找到元素

var rowTemplate= document.getElementsByName("rowTemplate");

var rowTemplate = document.getElementById("rowTemplate"); 

var rowTemplate = $('#rowTemplate');

然后再次尝试您的代码

rowTemplate.html().replace(....)

这个问题已经存在于: Uncaught TypeError : cannot read property 'replace' of undefined In Grid

【讨论】:

    猜你喜欢
    • 2021-11-03
    • 1970-01-01
    • 1970-01-01
    • 2014-06-14
    • 1970-01-01
    • 1970-01-01
    • 2021-12-22
    • 2018-03-24
    • 2015-01-06
    相关资源
    最近更新 更多