我正在尝试使用 Kendo DropDownList 并在列表顶部提供一个空白项目,以及使用模板提供多个列。
var ticketType = $("#TicketType").kendoDropDownList
({
dataTextField: "TicketTypeName",
dataValueField: "TicketTypeId",
optionLabel: " ", //This should add a blank item, but errors out instead.
dataSource:
{
serverFiltering: true,
type: "jsonp",
transport:
{
read:
{
url: "../Service/IncidentManagement.asmx/GetTicketTypeList",
contentType: "application/json; charset=utf-8",
type: "POST"
}
},
schema:
{
data: "d"
}
},
template: "<div><span>${TicketTypeName}</span><span>${TicketTypeDescription}</span></div>"
}).data("kendoDropDownList");
上面的结果
Uncaught ReferenceError: TicketTypeDescription is not defined
如果我没有下面指定的 optionLabel,则下拉列表可以正常工作(没有空项目)。
如果我指定了 optionLabel 并删除了模板选项,则它可以正常工作(无需多列)。
有什么方法可以检查它是否在模板中未定义?大致如下:
<span>${TicketTypeDescription} !== undefined ? ${TicketTypeDescription} : '' </span>
最佳答案
根据 Telerik 的回复:
The problem comes from the fact that the optionLabel does not know about the other properties of the data object. So you need to set some values, even empty ones, in order to work correctly.
因此,需要按如下方式指定 optionLabel:
optionLabel: {
TicketTypeName: " ",
TicketTypeId: "",
TicketTypeDescription: ""
}
关于kendo-ui - 带有空白项的 Kendo DropDownList 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24313309/