我试图根据所选项改变Kendo UI组合框的颜色。Kendo UI组合框事件
我已经把显示的问题[http://jsfiddle.net/PeWPE/]
我需要做的是确定所选择的项目在页面加载时什么小提琴。我可以捕获onDataBound事件,但在这一点上找不到选定的项目 - 我怀疑它不可用。
当用户从列表中选择一个新的项目选择事件给了我一切,我需要改变ComboBox的颜色数据,虽然颜色没有真正改变:(
所以,总之,有没有办法改变一个剑道UI组合框的颜色时,初始值设置(与固定我的语法任何帮助将是一件好事!)。
感谢您的帮助。
这里的代码...
$(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');
}
})
感谢@OnaBai的帮助。不幸的是,我不能在kendoComboBox()标记中设置初始值,它由knockout设置,并且在绑定时没有使用this.value。任何想法如何在这些情况下在绑定时间设置颜色? – user2208192
检查这个修改后的版本:http://jsfiddle.net/OnaBai/PeWPE/8/。在设置值之后,我调用trigger(“select”);'。这是一个稍微低一点的水平,但是当我们执行'value(9)'时,调用KendoUI不会调用的内容。你可能会意识到,我已经删除了'onSelect'上的'e'的引用,因为我没有将它作为参数传递给'trigger'。如果你需要它,你需要生成一个兼容版本的'e'并把它传递给'trigger'。我也删除了'onDataBound',因为如果你不设置初始值就不需要。 – OnaBai
感谢您的帮助,Kendo文档中似乎有很多不是! – user2208192