在 Ui 上,我已在弹出模式下打开 kendo-grid 进行编辑。其中有一个 kendoDropDownList 我已经绑定(bind)了一个更改事件。在更改事件函数中,我想更新同一剑道网格中存在的文本框的值。
到目前为止我已经尝试过:
在下拉列表的编辑器功能中,我可以访问选项,因此我尝试了 options.model.set("TEXT_BOX_FIELD", "Hello");
我也尝试过这个:
var uid = this.element.closest("[data-role=window]").data("uid");
var model = $("#Grid").data("kendoGrid").dataSource.getByUid(uid);
model.set("TEXT_BOX_FIELD","Hello");
在上述两种方法中,我发现即使控件在 chrome 调试器中传递了该行,该值也不会在模型中设置。
即使调用 set 函数后,model.TEXT_BOX_FIELD 仍保留空引号。 我无法理解其中的原因。
我还尝试在模型中设置值,如下所示:
model.TEXT_BOX_FIELD = "Hello";
通过这种方式,我可以在调试器中看到该值现在已在模型中设置,但它不会显示在网格的编辑弹出窗口中,尽管它在后台的 kendo-grid 中可见。
但是为了在弹出窗口中显示它,我使用了 jquery,如下所示:
$('[name="TEXT_BOX_FIELD"]').val("Hello");
这工作得很好,但我不明白为什么设置功能不起作用。
我遵循了kendo的文档和讨论如下: https://docs.telerik.com/kendo-ui/controls/data-management/grid/how-to/Editing/access-editor-control
https://www.telerik.com/forums/custom-popup-editor-with-additional-fields
https://www.telerik.com/forums/updating-a-textbox-cell-after-drop-down-selection
我想知道完成此任务的推荐方法。
编辑:
存在一个带有 return false
的验证,这会阻止 set 函数在定义架构时设置值。这是触发的,因为最初文本框的值为空。所以我删除了验证。现在 set() 函数运行正常,我也可以在 UI 上看到该值。
validation : {
requiredCheck : function(input) {
if (input.is("[name='TEXT_BOX_FIELD']") && input.val() == '') {
//alert(input.val())
input.attr("data-textBoxFieldMsg-msg", "Text Box cannot be empty");
return false;
}
return true;
}
}
最佳答案
我的解决方案:
首先我使用 jquery 设置文本框中的值,如下所示:
$('[name="TEXT_BOX_FIELD"]').val("Hello");
然后我调用模型的 set 函数来设置值,如下所示:
var uid = this.element.closest("[data-role=window]").data("uid");
var model = $("#Grid").data("kendoGrid").dataSource.getByUid(uid);
model.set("TEXT_BOX_FIELD","Hello");
这次,空验证在调用 model.set()
时没有抛出错误,因为该文本框的值已由 jQuery val()
设置功能。
关于jquery - 无法在下拉剑道网格 Angular 1 的更改事件中更新文本框值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47978523/