kendo.bind throws Uncaught TypeError: Cannot read property 'replace' of undefined

kendo.bind throws Uncaught TypeError: Cannot read property 'replace' of undefined

我在 kendo 绑定中遇到问题。我在 kendo 层次结构网格

中使用此代码

网格内

 { command: { text: "@PMEasy.Web.Localization.Project.Resource.ProjectSite", click: OpenProjectSite }, title: " ", width: "110px" },

然后

 function OpenProjectSite(e)
{
    var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
    $.ajax({
        url: "@Url.Action("GetCustomFieldForResource", "CustomField")",
        type: "POST",
        dataType: "json",
        data: { resourceId: dataItem.GUID },
        success: function (model) {

            if (model.dynamicFields.length > 0) {
                // convert the JSON to observable object
                var viewModel = kendo.observable(model);
                // bind the model to the container
                kendo.bind($("#customfield"), viewModel);
                var customfield = $("#customfield").data("kendoWindow");
                customfield.center();
                customfield.open();
            }
            else {
                alert('@PMEasy.Web.Localization.CustomField.Resource.NoCustomFieldDefined');
            }

        }
    });
}

在上面的 kendo 中绑定不起作用,抛出错误 - 未捕获的类型错误:无法读取未定义的 属性 'replace'

div需要绑定如下

  <div id="customfield" style="display:none">
    <div>
        <!-- container UL to host input fields -->
        <table border="1" cellpadding="1" cellspacing="1" style="width: 350px; margin:5px; font-size:12px">
            <tbody data-template="fieldsTemplate" data-bind="source: dynamicFields"></tbody>
            <tr>
                <td> &nbsp;</td>
                <td><input hidden id="ResourceId" data-bind="value:ResourceId" /><button id="save" type="button" onclick="SaveCustomField();">@PMEasy.Web.Localization.Resource.Resource.Save</button></td>
            </tr>
        </table>
    </div>
</div>

有帮助吗?可能是什么问题?

我发现了,我错过了定义字段模板。

我们应该这样定义

<script id="fieldsTemplate" type="text/x-kendo-template">
    <tr>
        <td><label style="margin-left:10px; margin-bottom:3px" data-bind="attr: { for: name}, text: label"></label># if (get("required")) {# <label style="color:red">*</label> #} #</td>
        <td>
            # if (get("type") == "text") {#
            <input style="margin-bottom:3px" class="k-input k-textbox" id="#:get('CustomFieldId') #" name="#:get('name') #" type="text" data-bind="value:textvalue" />
            #}else if (get("type") == "checkbox"){#
            <input style="margin-bottom:3px" id="#:get('CustomFieldId') #" name="#:get('name') #" class="k-input" type="checkbox" # if (get("boolvalue")) {# checked="checked" #} # />
            #}else if (get("type") == "date"){#
            <input data-type="date" id="#:get('CustomFieldId') #" name="#:get('name') #" data-bind="value:datevalue" data-role="datepicker" />
            #}else if (get("type") == "number"){#
            <input data-format="n0" id="#:get('CustomFieldId') #" name="#:get('name') #" data-bind="value:numbervalue" data-role="numerictextbox" />
            #}else if (get("type") == "cost"){#
            <input style="margin-bottom:3px" class="k-input k-textbox" id="#:get('CustomFieldId') #" name="#:get('name') #" type="text" data-bind="value:decimalvalue" />
            #}#
        </td>
    </tr>
</script>

现在可以使用了!!