来自 PopupEditor 的 Kendo UI 绑定下拉值 [英] Kendo UI bind drop down value from PopupEditor

查看:25
本文介绍了来自 PopupEditor 的 Kendo UI 绑定下拉值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Kendo Grid,它可以选择使用弹出式编辑器添加新记录.弹出式编辑器中的一个字段是 DropDownList.当我打开弹出编辑器时,我从下拉列表中预先选择了第一条记录.由于我预先选择了它,我希望它在网格中自动创建(绑定)(按更新"时)而无需再次手动选择.

解决方案

工作脚本: https://dojo.telerik.com/OFinidew/28

以下是一些有用的信息:

1.为您的数据源定义架构

模式是一种定义数据预期结构的方法.定义模式后,您的数据将被绑定".您将尽可能多地绑定数据,因为作为最后的手段,您最终将不得不使用模板.通常,Kendo UI 会尝试解决问题并自动绑定事物,但在特殊情况下,您必须为其提供架构.这是其中一种情况.

从代码示例来看,解决方法的方法似乎是尝试更改编辑"kendoGrid 的事件立即选择处理";状态 - 相反,您可以定义处理"状态(值2")作为状态"的默认值模型中的字段.但是,您需要确保您的自定义编辑器模板可以绑定到,这导致我们......

2.使用 HTML 属性:data-bind="value:(nameOfYourField)"

当您为剑道弹出窗口制作自己的编辑器模板时,它无法知道要绑定到 HTML 的哪个部分.请参阅提供的链接中的 statusDropdownEditorTemplate 作为如何完成此操作的示例.

3.valuePrimitive 是什么意思

通常,kendoDropDownList 将返回一个包含所选选项的文本和值的对象.但这不是我们在这种情况下想要的,因为状态被定义为0"、1"、2"等等.- 所以我们只是想要价值.当您将 valuePrimitive 设置为 true 时,您是在指示 kendoDropDownList 仅返回值本身,而不是包含所有内容的对象.

I have a Kendo Grid which has an option to add a new record using the Popup Editor. One field from the popup editor is a DropDownList. I have the first record from the dropdown list pre-selected when I open the Popup Editor. Since I pre-selected it, I would like it to be automatically created (bound) within the grid (when pressing "Update") without having to manually select it again. I have the example script here

解决方案

Working script: https://dojo.telerik.com/OFinidew/28

Here's a few things that are useful to know:

1. Defining schemas for your dataSources

A schema is a way to define what structure to expect from your data. When a schema is defined, your data will be "bound". As much as possible you'll want to bind your data, because as a last resort you'll end up having to use templates. Normally, Kendo UI will try to figure things out and get things bound automatically, but in special cases you'll have to give it a schema. This is one of those cases.

From the code sample, it seems like the approach of the workaround was to try change the "edit" event of the kendoGrid to immediately select the "Processing" status - Instead, you can define the "Processing" status (value "2") as the defaultValue of the "status" field in your model. But then, you'll need to make sure your custom editor template CAN be bound to, which leads us to..

2. Using the HTML property: data-bind="value:(nameOfYourField)"

When you're making your own editor templates for the kendo popup, it has no way of knowing what part of your HTML to bind to. See the statusDropdownEditorTemplate in the link provided as an example of how this is done.

3. What valuePrimitive means

Normally, a kendoDropDownList will return an object containing both the Text and Value of the selected choice. But this is not what we want in this case, because status is defined as "0", "1", "2" - so we just wanted the value. When you set valuePrimitive to true, you're instructing the kendoDropDownList to only return the value itself, not an object containing everything.

这篇关于来自 PopupEditor 的 Kendo UI 绑定下拉值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆