简体   繁体   English

使用敲出来为kendo-ui输入wrraper的宽度

[英]using knock-out for width of kendo-ui input wrraper

I work in durandal project (where javascript and html written in separated pages). 我在durandal项目中工作(javascript和html写在分隔的页面中)。 I have kendo-combo, and I give it width by declare the wrraper-input width. 我有kendo-combo,我通过声明wrraper-input宽度给它宽度。 It works well. 它运作良好。 But when I change it to be binded- it does not work. 但是,当我将其更改为绑定时 - 它不起作用。 here is my code (which is not working): 这是我的代码(不起作用):

html: HTML:

<input id="kendoCombo" data-bind=" value:'444', style:{width:width},
        kendoDropDownList: { dataSource: data,
        dataValueField:itemValue,
        dataTextField: itemText,
        value:selectedId,
        template: template,
        change:onChange}" />

javascript: JavaScript的:

width:ko.observable('100px')

When my width has not been binded yet, it works well. 当我的宽度尚未绑定时,它运作良好。 Here is my previous html code: 这是我之前的HTML代码:

<input style="width:100 
      id=" kendoCombo " 
      data-bind=" value: '444',
      kendoDropDownList: { dataSource: data,      
                           dataValueField:itemValue,
                           dataTextField: itemText,
                           value:selectedId, 
                           template: template,
                           change:onChange} " />

The problem is that Kendo only set the width of the DropDownList once when it is initialized, so when Knockout updates the width in the style binding it has no effect on the DropDownList . 问题是Kendo在初始化时只设置DropDownListwidth一次,因此当Knockout更新样式绑定中的width ,它对DropDownList没有影响。

However you can set width on the wrapper property (requires: Q1 2013 (version 2013.1.319) or newer) of the kendoDropDownList and you can put this logic into a custom bindingHandler: 但是你可以设置widthwrapper性质(要求:2013年第一季度(2013.1.319或版本)更新版本)中的kendoDropDownList ,你可以把这个逻辑到自定义bindingHandler:

ko.bindingHandlers.kendoDropDownListWidth = {
    update: function (element, valueAccessor) {
        var dropdownlist = $(element).data("kendoDropDownList");
        dropdownlist.wrapper[0].style["width"] = 
            ko.utils.unwrapObservable(valueAccessor());
    }
};

And use it like this: 并像这样使用它:

<input id="kendoCombo" data-bind=" value:'444', 
        kendoDropDownListWidth: width,
        kendoDropDownList: { dataSource: data,
        dataValueField:itemValue,
        dataTextField: itemText,
        value:selectedId,
        template: template,
        change:onChange}" />

Demo JSFiddle . 演示JSFiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM