我正在尝试根据所选项目更改 Kendo UI ComboBox 的颜色。
我整理了一个显示问题的小提琴[http://jsfiddle.net/PeWPE/]
我需要做的是在页面加载时确定所选项目。我可以捕获 onDataBound 事件,但此时找不到所选项目 - 我怀疑它不可用。
当用户从列表中选择一个新项目时,选择事件为我提供了更改组合框颜色所需的所有数据,尽管颜色实际上并没有改变:(
因此,总而言之,有没有办法在设置初始值时更改剑道 ui ComboBox 的颜色(并且修复我的语法的任何帮助也会很好!)。
谢谢你的帮助。
这是代码...
$(document).ready(function () {
// Create some data - including a color
var data = [{
text: "12 Angry Men",
value: "1",
color: "White"
}, {
text: "Il buono, il brutto, il cattivo.",
value: "2",
color: "White"
}, {
text: "Inception",
value: "3",
color: "Green"
}, {
text: "One Flew Over the Cuckoo's Nest",
value: "4",
color: "Green"
}, {
text: "Pulp Fiction",
value: "5",
color: "Blue"
}, {
text: "Schindler's List",
value: "6",
color: "Blue"
}, {
text: "The Dark Knight",
value: "7",
color: "Red"
}, {
text: "The Godfather",
value: "8",
color: "Red"
}, {
text: "The Godfather: Part II",
value: "9",
color: "Yellow"
}, {
text: "The Shawshank Redemption",
value: "10",
color: "Yellow"
}, {
text: "The Shawshank Redemption 2",
value: "11",
color: "Orange"
}];
// Create the combo
$("#movies").kendoComboBox({
dataTextField: "text",
dataValueField: "value",
dataSource: data,
height: 100,
change: onChange,
dataBound: onDataBound,
select: onSelect
});
// Select a value - Note no event is raised when doing this(!)
var combo = $("#movies").data("kendoComboBox");
combo.value("9");
function onChange(e) {
alert('onChange Called');
ctrl = this.element.attr("id");
var dataItem = this.dataItem(e.item.index());
}
// This is called - but the color is not being set
function onSelect(e) {
alert('onSelect Called');
var ctrl = this.element.attr("id");
var dataItem = this.dataItem(e.item.index());
alert('Control Id: ' +ctrl); // Check we've got the control
alert('Color selected: ' + dataItem.color);
$('input[name="' + ctrl + '_input"]').css({
backgroundColor: dataItem.color
});
$('#movies').css({
backgroundColor: dataItem.color
});
}
function onDataBound(e) {
alert('onDataBound Called');
}
})