0

我有 2 个文件:customer.jsadd-customer-template.html. 有一个网格,add-customer-template.html如下所示。

<div id="leadsGrid"  data-role="grid" 
                                                         data-bind="source: leadsDS"                                                     
                                                         date-scrollable="true"
                                                         data-editable="popup"
                                                         data-toolbar="['create']"
                                                         data-columns='[                                                                
                                                            {   
                                                                field: "salesPerson", title: "Sales Person", 
                                                                editor: "salesPersonDropDownEditor", 
                                                                template: "#= getSalesPersonName(salesPerson)#"
                                                            }, 
                                                            {field: "date", title: "Date", format: "{0:MM-dd-yyyy}"}, 
                                                            {field: "expectedDate", title: "Expected Date", format: "{0:MM-dd-yyyy}"}, 
                                                            {field: "expectedIncome", title: "Expected Income", format: "{0:c}"},
                                                            {field: "details", title: "Details"},
                                                            {field: "description", title: "Description"},
                                                            {command: ["edit", "destroy"], title: "&nbsp;"}]'>
                                    </div>

customer.js具有2个功能salesPersonDropDownEditorgetSalesPersonName如下所示。

var salesPersonDropDownEditor = function(container, options) {
              $('<input data-bind="value:' + options.field + '"/>')
                .appendTo(container)
                .kendoDropDownList({      
                  dataTextField: "salesPersonName",
                  dataValueField: "salesPersonID",
                  dataSource: new kendo.data.DataSource({
                            transport: {
                                read: {
                                    url: "../public/js/salesPersons.json",
                                    dataType: "json"
                                }
                            }
                        }) 
                });
            }

    var getSalesPersonName= function(salesPersonID) {
              for (var idx = 0, length = customerAdd.salesPersonData.length; idx < length; idx++) {
                  if (customerAdd.salesPersonData[idx].CategoryID === customerAdd.salesPersonData.salesPersonID) {
                    return customerAdd.salesPersonData[idx].salesPersonName;
                  }
              }
            }

我想在列上显示下拉列表,sales person但我收到错误salesPersonDropDownEditor未定义。当我在周围添加“”时,salesPersonDropDownEditor它不会引发错误。现在它的抛出错误getSalesPersonName没有定义。

从网格编辑时如何调用这些函数并显示下拉列表???

4

1 回答 1

1

这是关于使用声明性初始化(即使用data-属性来配置网格)的负面影响之一。您必须在customer.js文件中配置您的网格,使其与您的函数在同一范围内。

添加客户模板.html

<div id="leadsGrid"></div>

客户.js

$('#leadsGrid').kendoGrid({
  dataSource: leadsDS,
  scrollable: true,
  editable: 'popup',
  toolbar: ['create'],
  columns: [
    {   
      field: 'salesPerson', 
      title: 'Sales Person', 
      editor: salesPersonDropDownEditor, 
      template: getSalesPersonName
    },
    // shortened for brevity
  ]
});

var salesPersonDropDownEditor = function(container, options) {
  // hidden for brevity
};

var getSalesPersonName = function() {
  // hidden for brevity
};
于 2014-06-19T13:26:38.017 回答