我们有 Kendo 调度程序,我们在其中声明类别。在事件模型中,我们有categories
字段,它代表字符串数组。在调度程序声明中,我们也有资源,例如:
resources: [{
field: "categories",
dataSource: [{
text: "",
value: "red",
color: "#FF0000"
}, {
text: "",
value: "green",
color: "#00FF00"
}, {
text: "blue",
value: "blue",
color: "#0000FF"
}],
multiple: true,
title: "Category"
}],
在调度程序编辑模板中,我们有
<label for="categories">Categories</label>
<select data-bind="value:categories" name="categories" id="categories" multiple="multiple" data-placeholder="Select categories...">
</select>
并在调度程序edit(e)
回调中
var categ_editor = $("#categories").kendoMultiSelect({
dataTextField: "value",
dataValueField: "value",
itemTemplate: '<div class="k-state-default" style=\"width:100%; height:16px;\" ><div style=\"background-color:#:data.color#; width:14px; height:14px;display:inline-block;\" ></div> #: data.value #</div>',
tagTemplate: '<span class="k-state-default"><b style=\"background-color:#:data.color#;\" > </b> #: data.value #</span>',
dataSource: {
data: [{
text: "",
value: "red",
color: "#FF0000"
}, {
text: "",
value: "green",
color: "#00FF00"
}, {
text: "",
value: "blue",
color: "#0000FF"
}]
}
}).data("kendoMultiSelect");
因此,调度程序显示一切正常,并且正确处理多个值。但是当我编辑类别时,调度程序会像这样发送整个Category
对象(使用text
and color
)
"Categories": [{
"text": "",
"value": "red",
"color": "#FF0000"
}, {
"text": "",
"value": "green",
"color": "#00FF00"
}]
但正确的 JSON 必须是"Categories":["red","green"]"
如何解决这种行为?