kendo-ui - 无法从 Kendo Combobox 中获得价值
问题描述
我在 Kendo Grid 编辑器中使用以下代码,但无法从 Combobox 访问所选项目值的值。
此外,我在剑道下拉列表中做了同样的事情,但无法剑道组合框,所以如果有人有解决方案,请告诉我。
提前致谢 !
{
field: "SalesBookId",
title: "Sales Book",
template: "#= (typeof SalesBookId != 'undefined') ? GetSalesBookName(SalesBookId):'' #",
editor: function (container, options) {
$('<input required data-text-field="SalesBookName" data-value-field="SalesBookId" data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoComboBox({
autoBind: false,
dataSource: dsSalesBookDropDown,
});
}
},
解决方案
您没有显示dsSalesBookDropDown
,GetSalesBookName
因此也很难知道您的具体情况出了什么问题。
这个dojo演示了当配置、处理程序和数据都正确对齐时,应该不会有问题。
dojo 是基于示例“带有本地数据的网格”的,对于示例,您的SalesBook概念已更改为Seller。
与自定义编辑器相关的代码包括
var sellers = [
{ SellerId: 1, Name: "Andrew" },
{ SellerId: 2, Name: "Basil" },
{ SellerId: 3, Name: "Chuck" },
{ SellerId: 4, Name: "Dennis" },
{ SellerId: 5, Name: "Edward" }
];
var dsSellersDropDown = sellers;
function GetSellerName (id) {
var seller = sellers.find(function(x) {return x.SellerId == id });
return (seller) ? seller.Name : "** invalid id " + id + " **";
}
var products = [{
ProductID : 1,
ProductName : "Chai",
SellerId: 1,
SupplierID : 1,
CategoryID : 1,
. . .
网格配置
dataSource: {
data: products,
schema: {
model: {
fields: {
ProductName: { type: "string" },
SellerId: { type: "number" },
和
columns: [
"ProductName",
{ field: "SellerId",
title: "Seller Name",
template: "#= (typeof SellerId != 'undefined') ? GetSellerName(SellerId):'' #",
editor: function (container, options) {
$('<input required data-text-field="Name" data-value-field="SellerId" data-bind="value:'
+
options.field
+ '"/>')
.appendTo(container)
.kendoComboBox({
autoBind: false,
dataSource: dsSellersDropDown,
});
}
},
{ field: "UnitPrice", title: "Unit Price", format: "{0:c}", width: "130px" },
推荐阅读
- scala - 即使在增量编译中,SBT 1.3.8 也会自动更新 SNAPSHOT 版本
- c# - 对匿名类型调用 Equals 取决于创建对象的程序集
- java - 在 Java 中使用替换函数
- plugins - 编码 Minecraft 插件 (Jar)
- python - 如何在不使用 getpass() 的情况下在 python 中屏蔽或隐藏用户输入?
- terraform - Terraform 版本 12 ;1 个用于多个 amis 的 aws_instance 资源
- angular - 未定义 MIDI
- guidewire - 与查询相比,脚本返回有限数量的记录
- git - 如何强制 Visual Studio 使用 TFS 源代码控制提供程序而不是 GIT 提供程序
- excel - 从excel vba中另一个列表框中的选择中将项目添加到列表框