Knockoutを使用してマスター/詳細UIを作成しました。マスター上のitemselectedイベントハンドラーは、指定されたデータアイテムの詳細ビューをバインドします。これまでのところすべてが機能していますが、詳細領域にバインドされたデータにアクセスして、更新されたらサーバーに投稿できるようにしたいと思います。
私はKnockoutを初めて使用するので、これに対するより良いアプローチがあるかどうかアドバイスしてください。
//the master binding code
$.ajax({
url: getURL,
success: function (data) {
var viewModel = new itemModel(data);
var scope = document.getElementById("listContainer");
ko.cleanNode(scope);
ko.applyBindings(viewModel, scope);
}
//the viewmodel with event hander
function itemWrapper(item) {
this.SolutionSet = ko.observable(item.SolutionSet);
this.Insight = ko.observable(item.Insight);
this.DateFrom = ko.observable(item.DateFrom);
this.DateTo = ko.observable(item.DateTo);
}
var itemModel = function (data) {
var self = this;
var observableData = ko.utils.arrayMap(data, function (item) {
return new itemWrapper(item);
});
self.items = ko.observableArray(observableData);
onItemSelected = function (data) {
var scope = document.getElementById("itemEditor");
ko.cleanNode(scope);
ko.applyBindings(data, scope);
};
}