zoukankan      html  css  js  c++  java
  • knockoutjs(03) ko + jquery ui

    <h1 class="header" data-bind="text: label"></h1>
    
    <div id="dialog" data-bind="dialog: {autoOpen: false, title: 'Dialog test' }, dialogVisible: isOpen">foo dialog</div>
    
    <div>
        <button data-bind="click: open">Open</button>
        <button data-bind="click: close" >Close</button>
    </div>
    
    <hr/>
    
    <div data-bind="text: ko.toJSON($root)"></div>
    ko.bindingHandlers.dialog = {
            init: function(element, valueAccessor, allBindingsAccessor) {
                var options = ko.utils.unwrapObservable(valueAccessor()) || {};
                //do in a setTimeout, so the applyBindings doesn't bind twice from element being copied and moved to bottom
                setTimeout(function() { 
                    options.close = function() {
                        allBindingsAccessor().dialogVisible(false);                        
                    };
                    
                    $(element).dialog(options);          
                }, 0);
                
                //handle disposal (not strictly necessary in this scenario)
                 ko.utils.domNodeDisposal.addDisposeCallback(element, function() {
                     $(element).dialog("destroy");
                 });   
            },
            update: function(element, valueAccessor, allBindingsAccessor) {
                 var shouldBeOpen = ko.utils.unwrapObservable(allBindingsAccessor().dialogVisible);
                 $(element).dialog(shouldBeOpen ? "open" : "close");
                 
            }
    };
        
    
    var viewModel = {
        label: ko.observable('dialog test'),
        isOpen: ko.observable(false),
        open: function() {
           this.isOpen(true);   
        },
        close: function() {
           this.isOpen(false);   
        }
    };
    
    ko.applyBindings(viewModel);
            
    .header {
        font-size: 16px;
        font-family: sans-serif;
        font-weight: bold;
        margin-bottom: 20px;
    }

    http://jsfiddle.net/rniemeyer/SnPdE/

    ----------------------------------- http://www.cnblogs.com/rock_chen/
  • 相关阅读:
    数据库常用术语
    灾备模式的基本体系架构
    linux下的c++开发
    视图矩阵的推导-opengl应用
    抓包实例
    以软件推动工业进步 -嵌入式学习网站
    web 前端 转盘界面
    web 汇率
    xml
    高性能网站架构设计之缓存篇(4)- 主从复制
  • 原文地址:https://www.cnblogs.com/rock_chen/p/2732760.html
Copyright © 2011-2022 走看看