Kendo-Knockout:如何将窗口居中 [英] Kendo-Knockout: How to center window
问题描述
我正在使用RPNiemeyer的kendo-knockout库.我有一个kendo窗口,在html中像这样使用:
I am using RPNiemeyer`s kendo-knockout library. I have a kendo window which I use like this in the html:
<div data-bind="kendoWindow: { isOpen: isOpen, title:'States', width: 600, height: 150, modal: true, resizable: false, actions: ['Maximize', 'Close'] }" > </div>
我曾经这样居中放置对话框:
I used to center the dialog like this:
$('#productionStates').data("kendoWindow").center();
但是由于center
是一种方法,因此我无法像center: true
这样在标记中传递它.在kendo-knockout文档中,某些小部件有一个属性小部件,我想这是关键,但是我不确定如何使用它,因为没有示例.任何想法都将受到欢迎.谢谢!
But as center
is a method I cannot pass it in the markup like this center: true
. In the kendo-knockout documentation there is a property widget for some of the widgets and my guess is that this is the key but I am not sure how to use it as there are no examples. Any ideas will be welcome. Thanks!
推荐答案
当需要以提供的绑定选项不支持的方式与窗口小部件进行交互时,可以使用widget
参数.通常,这是不得已的做法,但在这种情况下,这似乎是正确的选择.
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.
您要做的是将一个observable传递给widget
参数,它将被实际的小部件填充.然后,您可以从视图模型中调用方法.
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.
类似的东西:
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();
};
然后,在标记中:
<div data-bind="kendoWindow: { isOpen: isOpen, visible: false, modal: true, widget: myWidget }">
...
</div>
此处提供示例: http://jsfiddle.net/rniemeyer/gNgDm/
这篇关于Kendo-Knockout:如何将窗口居中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!