我在持续性项目中工作,我想知道:如何定义kendo组合框的宽度?
我在链接设置kendo ui下拉列表宽度上看到了这个问题,但是答案对我没有好处,因为我不想使用组合式Id。
(为什么没有简单的方法将其作为组合式属性来实现,就像您可以简单地定义它的高度一样?)
以下是我的html代码:
<input id="myCombo" data-bind=" value:'444',
kendoDropDownList: { dataSource: data,
dataValueField:itemValue,
dataTextField: itemText,
value:selectedId,
}" />发布于 2013-12-29 15:52:41
我猜没有width选项,因为小部件默认为输入的宽度,所以对于典型的用例,不需要单独指定宽度。如果您希望为下拉容器的宽度提供一个单独的选项,您可以简单地创建自己的小部件来读取listWidth选项:
(function ($) {
var ui = kendo.ui,
DropDownList = ui.DropDownList;
var CustomDropDownList = DropDownList.extend({
init: function (element, options) {
DropDownList.fn.init.call(this, element, options);
if (options.listWidth) {
this.list.width(options.listWidth);
}
},
options: {
name: 'CustomDropDownList'
}
});
ui.plugin(CustomDropDownList);
})(jQuery);然后您可以像这样使用:
$("#c2").kendoCustomDropDownList({
dataTextField: "text",
dataValueField: "value",
listWidth: 400,
dataSource: [{
text: "Item1",
value: "1"
}, {
text: "Item2",
value: "2"
}]
});如果您想以声明的方式声明listWidth,可以使用像下面这样的init方法:
init: function (element, options) {
options.listWidth |= $(element).attr('data-list-width');
DropDownList.fn.init.call(this, element, options);
if (options.listWidth) {
this.list.width(options.listWidth);
}
}然后像这样使用:
<input data-role='customdropdownlist' data-list-width="150"/>演示这里。
https://stackoverflow.com/questions/20826110
复制相似问题