2014-06-19 40 views
0

不確定我有2個文件:customer.jsadd-customer-template.html。如下所示,add-customer-template.html上有一個網格。劍道UI - 數據列模板函數以格

<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未定義。

如何調用這些功能和顯示下拉列表中,同時從電網編輯???

回答

1

這是使用聲明性初始化(即使用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 
}; 
+0

我使用MVVM模式,所以我以這樣的方式進行配置。我如何調用這個模式???這些功能 - @Brett – Valay

+0

我不必在文件級JS @Brett – Valay

+0

配置電網能否請你讓我知道如何在我的現有代碼調用這些函數??? – Valay