我有一个网格,其中一些列是布尔值(true/false)。我希望它们在列中显示为"是/否"。我还使用下拉菜单来更改值。我遇到的问题是,一旦我选择了下拉下的值形式,它就不会在我离开行时显示新值。但是,只有我从"否"到"是"。我认为这与我的模板和下拉下的互动有关吗?该值没有从下拉列表中设置为"是"的模板,因此它属于" no"逻辑。
这是我下拉的数据:
indData = [
{ Text: "Yes", boolValue: "true" },
{ Text: "No", boolValue: "false" }
];
和我对该列的定义:复制代码
{
field: "FreeAndReducedInd", width: "150px",
editor: indDropDownEditor,
title: "Free and Reduced",
template: ("# if (FreeAndReducedInd == true) { #" + "Yes" + "# } else { #" + "No" + "#}#")
},
和编辑器代码:
复制代码
函数inddropdowneditor(容器,选项){
$('<input data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList({
dataTextField: "Text",
dataValueField: "boolValue",
dataSource: indData
});
};
我错了什么?
谢谢
丽莎
更新 - 我得到了Kendo的答案,他们建议我添加一个自定义粘合剂,并且似乎正在工作。
kendo.data.binders.widget.boolValue = kendo.data.Binder.extend({
init: function (widget, bindings, options) {
kendo.data.Binder.fn.init.call(this, widget.element[0], bindings, options);
this.widget = widget;
this._change = $.proxy(this.change, this);
this.widget.bind("change", this._change);
},
refresh: function () {
var value = this.bindings.boolValue.get();
this.widget.value(value.toString());
},
change: function () {
var value = this.widget.value();
this.bindings.boolValue.set(value === "true");
},
destroy: function () {
this.widget.unbind("change", this._change);
}
});
我还修改了我的编辑器:
function indDropDownEditor(container, options) {
$('<input data-bind="boolValue:' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList({
dataTextField: "Text",
dataValueField: "boolValue",
dataSource: [
{ Text: "Yes", boolValue: "true" },
{ Text: "No", boolValue: "false" }
]
});
};
如果您可以给我们完整的代码,那会更好。在提供任何解决方案之前,更容易在本地检查。但是尝试在模板中使用以下内容。如果没有帮助,请使用完整的代码更新您的帖子,以便我可以重新检查。谢谢。
template: "<td role='gridcell'> #= FreeAndReducedInd == true ? 'Yes' : 'No' # </td>"