Hot Towel SPA Durandal Knockout and Dynatree

﹥>﹥吖頭↗ 提交于 2019-12-24 11:27:45

问题


I am trying to get the dynatree control to work in the Hottowel viewmodel, based on this fiddle, 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());

Having trouble understanding how to edit the vm to incorporate the dynatree ko.


回答1:


First off, you shouldn't be binding your viewmodel explicitly; let Durandal do this for you. Next, you can register any knockout binding handlers at the outset by placing the binding handler in either the main.js or the shell.js file's activate method. This way, you guarantee that the binding handler is available to all viewmodel/view combinations at binding time.



来源:https://stackoverflow.com/questions/15412386/hot-towel-spa-durandal-knockout-and-dynatree

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!