我會用以前問問題的代碼小的改動綁定元素的值時,但情況是不同的突破:劍道淘汰賽:綁定改變
Kendo-Knockout: Closing window breaks bindings
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.close = function() {
self.isOpen(false);
}
};
var elementIsBound = function (elementId) {
return !!ko.dataFor(document.getElementById(elementId));
};
var myProductionStatesList = ko.observable();
var openPopUp = function(){
myProductionStatesList(new ProductionStatesList());
if (!elementIsBound("productionStates")){
ko.applyBindings(myProductionStatesList, document.getElementById("productionStates"));
}
myProductionStatesList().openPopUp();
}
myProductionStatesList
是可觀察的。點擊彈出的按鈕打開,我正在實例化ProductionStatesList
視圖模型並將其值分配給myProductionStatesList
。第一次點擊按鈕時,每個按鈕都可以正常工作。當您關閉彈出窗口並再次單擊該按鈕時,綁定被破壞並且沒有任何反應。我期待每按一下按鈕,生產狀態清單的新實例將被反彈,因爲myProductionStatesList
是可觀察的。我錯過了什麼?
的jsfiddle: