Kendo-Knockout: How to center window

妖精的绣舞 提交于 2019-12-05 08:38:49

The widget parameter is intended to be used when you need to interact with a widget in a way that is not supported by the provided binding options. Normally, this is kind of a last resort, but in this case it looks like it would be the right choice.

What you do is pass an observable into the widget parameter and it will get filled with the actual widget. Then, you can call methods off of it from your view model.

Something like:

var ViewModel = function() {
   this.isOpen = ko.observable(false);
   //center it if it is opened
   this.isOpen.subscribe(function(newValue) {
       if (newValue) {
           this.myWidget().center();         
       }
   }, this);

   //hold the widget
   this.myWidget = ko.observable();
};

Then, in markup:

<div data-bind="kendoWindow: { isOpen: isOpen, visible: false, modal: true, widget: myWidget }">
     ...
</div>​

Sample here: http://jsfiddle.net/rniemeyer/gNgDm/

I actually achieved the same effect as Niemeyer by sticking it in the binding handler:

 

    ko.bindingHandlers.kendoWindow.options = {
        open: function () { this.element.data('kendoWindow').center(); }
    };

No additional binding needed, but it does tie up your "onOpen" event.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!