我有两个文件:customer.js
和add-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: " "}]'>
</div>
customer.js
有2个函数salesPersonDropDownEditor
和getSalesPersonName
,如下所示。
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
未定义。
如何在从网格编辑时调用这些功能并显示下拉列表???
答案 0 :(得分: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
};