用于使用MultiSelect
在网格中,有几个问题需要考虑:
- 网格编辑器仅支持列类型
string
, boolean
, number
and date
。因为你想要保存一个数组......让我们说string
你必须解决这个问题。
- 由于您正在从服务器接收值数组,因此您必须使用
template
将其序列化为string
为了显示从服务器接收到的值。
- Kendo UI 无法猜测您想要使用多选作为输入,因此您必须提供和
editor
功能。
让我们解决所有这些问题:
为了解决以下问题array
of string
最简单的解决方案是不对 KendoUI 说出任何有关接收内容的信息。
For the template
,我将使用 JavaScriptjoin
方法将所有值放在一起,并用“,”分隔。就像是:
{ field: "Cities", template: "#= Cities.join(', ') #" }
最后对于编辑器,我使用:
{ field: "Cities", template: "#= Cities.join(', ') #", editor : citiesEditor }
function citiesEditor(container, options) {
$("<select multiple='multiple' data-bind='value : Cities'/>").appendTo(container).kendoMultiSelect({
dataSource: citiesDS
});
}
在我的情况下哪里citiesDS
只是一个array
of string
带有有效城市的名称。
var citiesDS = [
"Boston", "Kirkland", "London", "New York", "Philadelphia", "Redmond", "Seattle", "Tacoma"
];
当您更新(保存)时,它会向主机发送一个array
包含城市的字符串Cities
field.
示例:这里http://jsfiddle.net/OnaBai/Q2w7z/ http://jsfiddle.net/OnaBai/Q2w7z/