나는 다음과 같은 모델이 있습니다새로 고침 뷰 모델 관찰 변화에 대한 예를 들어
var Volume = function (id, path, isactive) {
var self = this;
self.id = ko.observable(id);
self.path = ko.observable(path);
self.isactive = ko.observable(isactive);
self.Save = function (data) {
//ajax post
}
self.Update = function (data) {
//ajax post
}
}
var ViewModel = function (data) {
var self = this;
self.volumes = ko.observableArray(data.volumes.map(function (item) {
return new Volume(item.id, item.path, item.isActive, item.description);
}));
self.AddVolume = function() {
self.volumes.push(new Volume());
}
}
저장 또는 업데이트 후, 내가 어떤 값이 데이터베이스에 변경 되었기 때문에, 볼륨 모델에서 부모 뷰 모델을 새로 고칠를.
어떻게하면 ViewModel을 다시 초기화 할 수 있습니까?
var viewModel = new ViewModel(ko.utils.parseJson(data) || []);
ko.applyBindings(viewModel);
부모 ViewModel_을 (를) _refresh한다는 것은 무엇을 의미합니까? –
ViewModel에 새로운 데이터 바인딩하기 – capiono
'Save'와'Update' ajax 콜백에서 현재'Volume'을 업데이트합니까? –