热毛巾SPA Durandal淘汰赛和Dynatree [英] Hot Towel SPA Durandal Knockout and Dynatree

查看:97
本文介绍了热毛巾SPA Durandal淘汰赛和Dynatree的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于这个小提琴 http://jsfiddle,我试图使dynatree控件在Hottowel视图模型中工作.网络/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.

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

推荐答案

首先,您不应该明确绑定视图模型;让Durandal为您做到这一点.接下来,您可以通过将绑定处理程序放置在main.js或shell.js文件的activate方法中,一开始就注册任何敲除绑定处理程序.这样,您可以确保绑定处理程序在绑定时可用于所有viewmodel/view组合.

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.

这篇关于热毛巾SPA Durandal淘汰赛和Dynatree的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆