1
我必須檢查視圖中是否存在任何變化。在這裏,我無法將模型與表單綁定。針對isdirty功能的敲除綁定
我認爲網頁的代碼是: -
<section>
<ul class="breadcrumb" role="menu">
<li><i class="fa fa-home"></i> <a href="#">Home</a><span class="divider"></span></li>
<li class="active"><i class="fa fa-office"></i> <span>Company</span></li>
</ul>
<div class="row">
<div class="col-lg-12" data-bind="event:{change:dirty}">
<div data-bind="tabs:{widgetData:widgetData}"></div>
</div>
</div>
</section>
和我寫檢查isDirty代碼的部分是: -
var vm = {
activate: activate,
canDeactivate: canDeactivate,
dirty: function (root) {
var _initialized;
var result = ko.computed(function() {
if (!_initialized) {
ko.toJS(root);
_initialized = true;
return false;
}
return true;
});
return result;
},
};
function canDeactivate() {
if (vm.dirty == true) {
var app = require('durandal/app');
return app.showMessage('Are you sure you want to leave this page?', 'Navigate', ['Yes', 'No']);
} else {
return true;
}
}
...和您的問題是? – 2014-09-22 14:07:50
我的問題是,如何將模型綁定到模型,我可以在窗體中進行任何更改時檢查其是否髒。 – user3206357 2014-09-22 14:11:37