0
我已經在測試函數中更新了observable item屬性。 此更新已成功更新可觀察項目。Knockout可觀察的更新但不更新UI?
因爲我在調試中檢查它。
但標籤不更新。 有什麼不對?
i try item.serviceResult = ko.observable(「TESTING ...」); 和其他東西,但用戶界面標籤不更新。
的Javascript代碼:
var ViewModel = function (myPano) {
var observablePano = ko.utils.arrayMap(myPano, function (panoData) {
return {
panoNo: ko.observable(panoData.panoNo),
modemNo: ko.observable(panoData.modemNo),
aydinlatmaNo: ko.observable(panoData.aydinlatmaNo),
geneltuketimNo: ko.observable(panoData.geneltuketimNo),
serviceResult: ko.observable(panoData.serviceResult),
test: function (item) {
alert(item.panoNo());
item.serviceResult = "TESTING...";
}
};
});
this.Panos = ko.observableArray(observablePano);
};
$(function() {
var viewModel = new ViewModel(
[
{ panoNo: '1', modemNo: '', aydinlatmaNo: '', geneltuketimNo: '', serviceResult: '.' },
{ panoNo: '2', modemNo: '', aydinlatmaNo: '', geneltuketimNo: '', serviceResult: '.' },
{ panoNo: '3', modemNo: '', aydinlatmaNo: '', geneltuketimNo: '', serviceResult: '.' },
{ panoNo: '4', modemNo: '', aydinlatmaNo: '', geneltuketimNo: '', serviceResult: '.' },
{ panoNo: '5', modemNo: '', aydinlatmaNo: '', geneltuketimNo: '', serviceResult: '.' },
{ panoNo: '6', modemNo: '', aydinlatmaNo: '', geneltuketimNo: '', serviceResult: '.' }
]
);
ko.applyBindings(viewModel);
});
html : <div class="row show-grid" data-bind="foreach: Panos">
<div class="col-xs-6 col-md-4">
<table>
<tr>
<td>
<form class="form-horizontal">
<fieldset>
<div class="input-group">
<input type="text" placeholder="PANO NO" class="form-control" data-bind="value: panoNo">
</div><div class="input-group">
<input type="text" placeholder="MODEM NO" class="form-control" data-bind="value: modemNo">
</div><div class="input-group">
<input type="text" placeholder="AYDINLATMA SAYAÇ NO" class="form-control" data-bind="value: aydinlatmaNo">
</div><div class="input-group">
<input type="text" placeholder="GENEL TÜKETİM SAYAÇ NO" class="form-control" data-bind="value: geneltuketimNo">
</div>
</fieldset>
</form>
</td>
<td>
<button type="button" class="btn btn-primary" data-bind="click: test">Testi Başlat</button>
<br />
<span class="label label-default" data-bind="text: serviceResult"></span>
</td>
</tr>
</table>
</div>
</div>
這是真的,我忘記了這一點。 – wikiCan 2014-09-04 09:51:24