首页 > 解决方案 > 无法从 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,

                            });
                    }
                },

标签: kendo-uikendo-combobox

解决方案


您没有显示dsSalesBookDropDownGetSalesBookName因此也很难知道您的具体情况出了什么问题。

这个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" },

推荐阅读