遗漏的类型错误:无法读取属性“取代”的未定义(Uncaught TypeError: Cannot

2019-10-19 23:45发布

我在使用剑道电网和剑道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>

谢谢 :)

Answer 1:

我认为jQuery的找不到元素。

首先,找到元素

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

要么

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

要么

var rowTemplate = $('#rowTemplate');

然后再次尝试你的代码

rowTemplate.html()。代替(....)

这个问题已经可以在: 遗漏的类型错误:无法读取属性“取代”的不确定网格



文章来源: Uncaught TypeError: Cannot read property 'replace' of undefined