我试图让 dynatree 控件在 Hottowel 视图模型中工作,基于这个小提琴,http://jsfiddle.net/EZgNs
var ViewModel = function() {
var self = this;
self.initialized = ko.observable(false);
self.items = ko.observableArray();
// Use JSFiddle echo to simulate an AJAX service
(function() {
$.ajax({ url:"/echo/json/", data:data, type:"POST",
success:function(data)
{
// Map the returned JSON to the View Model
ko.mapping.fromJS(data, {}, self.items);
self.initialized(true);
}
});
})();
};
ko.bindingHandlers.dynatree = {
update: function(element, valueAccessor, allBindingsAccessor, viewModel) {
setTimeout( function() { $(element).dynatree()}, 0);
}
};
ko.applyBindings(new ViewModel());
无法理解如何编辑 vm 以合并 dynatree ko。