我正在使用 RPNiemeyer 的 kendo-knockout 库。我有一个 onclick 实例化 javascript 对象的按钮,将 div 绑定到该对象并打开一个弹出窗口。当我从右上角的 x 按钮关闭窗口时(我没有导入图像并且在小提琴中没有正确显示它。),绑定被破坏并且按钮不会再次打开窗口。这是我的html:
<button onclick="openPopUp()">OpenPopUp</button>
<div id="productionStates" class="hidden">
<div data-bind="kendoWindow: { isOpen: isOpen, title:'States', center:true, width: 600, height: 150, modal: true, resizable: false, actions: ['Maximize', 'Close'] }" >
<fieldset>
<legend>Change state:</legend>
<table>
<tr data-bind="foreach: productionStates">
<td><button class="k-button" data-bind="value: ProductionState, text: ProductionState" /></td>
</tr>
</table>
</fieldset>
</div>
</div>
javascript:
var ProductionStatesList = function() {
var
self = this;
ProductionStatesList.prototype.productionStates =
ko.observableArray([ { ProductionState: ko.observable("Pending") } ]);
ProductionStatesList.prototype.openPopUp = function () {
self.isOpen(true);
};
ProductionStatesList.prototype.isOpen = ko.observable(false);
ProductionStatesList.prototype.openPopUp = function () {
self.isOpen(true);
};
ProductionStatesList.prototype.close = function () {
self.isOpen(false);
}
};
var elementIsBound = function (elementId) {
return !!ko.dataFor(document.getElementById(elementId));
};
var openPopUp = function(){
var productionStatesList = new ProductionStatesList();
if (!elementIsBound("productionStates")){
ko.applyBindings(productionStatesList, document.getElementById("productionStates"));
}
productionStatesList.openPopUp();
}
这是 jsfiddle 中的代码:http: //jsfiddle.net/5Zkyg/40/
重现步骤:
1.单击按钮。弹出窗口打开。
2.从右上方的图像关闭窗口(x按钮不可视化,因为图像未导入)。
请解释这不起作用的原因,任何解决方案将不胜感激。谢谢!