簡體   English   中英

kendo ui-網格中未定義數據列模板功能

[英]kendo ui - data-column template function is undefined in grid

我有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

從網格編輯時,如何調用這些函數並顯示下拉列表?

這是使用聲明式初始化(​​即使用data-屬性配置網格)的負面影響之一。 您必須在customer.js文件中配置網格,使其與您的函數處於同一范圍。

附加客戶template.html

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

customer.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
};

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM