HTML

<div id="modalAreaID01">
    <button type="button" class="btn btn-primary btn-lg" data-toggle="modal"
            data-bind="attr: { 'data-target': modalWindowId },click:modalWindowLoad">
        Launch demo modal
    </button>
</div>
<script src="Content/jquery-2.1.1.min.js"></script>
<script src="Content/bootstrap-3.2.0-dist/js/bootstrap.min.js"></script>
<link href="Content/bootstrap-3.2.0-dist/css/bootstrap.min.css" rel="stylesheet" />
<script src="Content/knockout-3.1.0.min.js"></script>
<script src="Content/knockout.mapping.js"></script>
<script src="index.js"></script>

JS

var buidModelWindow = function (showWindowId,dataSorce, htmlAreaID, selectAllKOAction, saveKOAction, closeKOAction) {
    var html = "<div class='modal fade' id='" + showWindowId + "' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>"
    + "    <div class='modal-dialog'>"
    + "        <div class='modal-content'>"
    + "            <div class='modal-header'>"
    + "                <button type='button' class='close' data-dismiss='modal' data-bind='click:" + closeKOAction + "'><span aria-hidden='true'>&times;</span><span class='sr-only'>Close</span></button>"
    + "                <h4 class='modal-title' id='myModalLabel'>Modal title</h4>"
    + "            </div>"
    + "            <div class='modal-body'>"
    + "<!"+"-- ko foreach:"
    + dataSorce
    + " -->"
    + "<label><input type='checkbox' data-bind='checked:Enabled' /> <span data-bind='text:Value' /></label>"
    + "<!-- /ko -->"
    + "            </div>"
    + "            <div class='modal-footer'>"
    + "                <button type='button' class='btn btn-primary' data-bind='click:" + selectAllKOAction + "'>SelectAll</button>"
    + "                <button type='button' class='btn btn-default' data-dismiss='modal' data-bind='click:" + closeKOAction + "'>Close</button>"
    + "                <button type='button' class='btn btn-primary' data-bind='click:" + saveKOAction + "'>Save changes</button>"
    + "            </div>"
    + "        </div>"
    + "    </div>"
    + "</div>"
    $("#" + htmlAreaID + "").append(html);
}
var ViewModel = function (data) {
    var self = this;
    self.modelList = ko.mapping.fromJS(data);
    self.modalAreaID = ko.observable("modalAreaID01");
    self.modalWindowId = ko.observable("#modalWindowId01");
    self.modalWindowForeachID = ko.observable("modelList");
    self.isAll = ko.observable(false);
    self.save = ko.observable(false);
    var indexAndEnabled = new Array();
    self.selectAll = function () {
        if (self.isAll() == false) {
            ; i < self.modelList().length; i++) {
                self.modelList()[i].Enabled(true);
            }
            self.isAll(true);
        }
        else {
            ; i < self.modelList().length; i++) {
                self.modelList()[i].Enabled(false);
            }
            self.isAll(false);
        }
    }
    self.saveKOAction = function () {
        self.save(true);
        ; i < self.modelList().length; i++) {
            indexAndEnabled[i] = self.modelList()[i].Enabled();
        }
    }
    self.closeKOAction = function () {
        if (self.save() == false) {
            for (i in indexAndEnabled)
            {
                self.modelList()[i].Enabled(indexAndEnabled[i]);
            }
        } else {
        }
    }
    self.modalWindowLoad = function () {
        self.save(false);
        ; i < self.modelList().length; i++) {
            indexAndEnabled[i] = self.modelList()[i].Enabled();
        }
    }
    buidModelWindow(self.modalWindowId().substring(),
                    self.modalWindowForeachID(),
                    self.modalAreaID(),
                    "selectAll", "saveKOAction", "closeKOAction");
}
$(function () {
    var data =jQuery.parseJSON('{"KVPEList":[{"Key":null,"Value":"阿富汗","UIID":"uiid_Country_101","Enabled":false,"Pattern":"101","Percentage":-1},{"Key":null,"Value":"巴林","UIID":"uiid_Country_102","Enabled":false,"Pattern":"102","Percentage":-1},{"Key":null,"Value":"孟加拉国","UIID":"uiid_Country_103","Enabled":false,"Pattern":"103","Percentage":-1}],"Enabled":false}');
    ko.applyBindings(new ViewModel(data.KVPEList));

});

代码下载:http://files.cnblogs.com/badnewfish/modalWindowKO.rar

KO+bootstrap 模态窗全选绑定的更多相关文章

  1. BootStrap iCheck插件全选与获取value值的解决方法

    这篇文章主要介绍了BootStrap iCheck插件全选与获取value值的解决方法,解决方法其实很简单,下面小编给大家分享下这方面的知识 在使用jQuery iCheck 插件的时候遇到了一个问题 ...

  2. 解决jquery-ui-autocomplete选择列表被Bootstrap模态窗遮挡的问题

    最近在一个ASP.NET MVC5项目中使用Bootstrap的模态窗(弹出层)来让用户填写内容,其中的一个编辑框提供了自动完成功能,用jQuery UI Autocomplete来实现. 因为我是W ...

  3. jQuery ui autocomplete选择列表被Bootstrap模态窗遮挡的完美解决方法

    转:http://www.cnblogs.com/wiseant/p/4553837.html 最近在一个ASP.NET MVC5项目中使用Bootstrap的模态窗(弹出层)来让用户填写内容,其中的 ...

  4. bootstrap实现checkbox全选、取消全选

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <!-- 最新版本的 ...

  5. 使用AngularJS实现简单:全选和取消全选功能

    这里用到AngularJS四大特性之二----双向数据绑定 注意:没写一行DOM代码!这就是ng的优点,bootstrap.css为了布局,JS代码也只是简单创建ng模块和ng控制器 效果: < ...

  6. MVC身份验证.MVC过滤器.MVC6关键字Task,Async.前端模拟表单验证,提交.自定义匿名集合.Edge导出到Excel.BootstrapTree树状菜单的全选和反选.bootstrap可搜索可多选可全选下拉框

    1.MVC身份验证. 有两种方式.一个是传统的所有控制器继承自定义Control,然后再里面用MVC的过滤器拦截.所以每次网站的后台被访问时.就会先走入拦截器.进行前端和后端的验证 一个是利用(MVC ...

  7. Bootstrap, 模态框实现值传递,自动勾选

    目录 Bootstrap,模态框自动勾选,值传递 1.父页面 2. 子页面(modal) 模态框 Bootstrap,模态框自动勾选,值传递 场景: ​ 有一个这样的需求, 在父页面有一个table, ...

  8. FlexiGrid 使用 全选、自动绑定

    1.介绍 Flexigrid是一个类似于Ext Gird,但基于jQuery开发的Grid.它具有的功能包括:可以调整列宽,合并列标题,分页,排序,显示/隐藏表格等.Flexigrid显示的数据能够通 ...

  9. Bootstrap模态弹出窗

    Bootstrap模态弹出窗有三种方式: 1.href触发模态弹出窗元素: <a class="btn btn-primary" data-toggle="moda ...

随机推荐

  1. 20145224&20145238 《信息安全系统设计基础》第二次实验

    20145224&20145238 <信息安全系统设计基础>第二次实验 课程:信息安全系统设计基础 班级:1452 姓名:陈颢文 荆玉茗 学号:20145224 20145238 ...

  2. C#窗体 LISTVIEW

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  3. Javascript之链式运动框架1

    第一部分:HTML内容: <script src="6-1.js"></script> <script> window.onload=funct ...

  4. UVA 1349(二分图匹配)

    1349 - Optimal Bus Route Design Time limit: 3.000 seconds A big city wants to improve its bus transp ...

  5. ReferentialConstraint 中的依赖属性映射到由存储生成的列

    ReferentialConstraint 中的依赖属性映射到由存储生成的列 这个问题是由于从表中的外键关系建立错误(可能是由于误改),查看从表的所有外键关系,即可找到问题所在. 问题: 什么是从表? ...

  6. 如何获取有性能问题的SQL

    1.通过用户反馈获取存在性能问题的SQL.   2.通过慢查日志获取存在性能的SQL.   启动慢查日志 slow_query_log=on   set global slow_query_log=o ...

  7. HTTP-Session工作机制

    HTTP-Session将HTTP这种无状态协议通过session来保存状态.然而session通过记录服务器生成编号来标识协议,从而服务器就可以识别协议的状态. session保存服务器端,  co ...

  8. iOS开发Swift篇—(五)元组类型

    iOS开发Swift篇—(五)元组类型 一.元组类型介绍 1.什么是元组类型 元组类型由 N个 任意类型的数据组成(N >= 0),组成元组类型的数据可以称为“元素” 示例: let posit ...

  9. iOS开发拓展篇—应用之间的跳转和数据传递

    iOS开发拓展篇—应用之间的跳转和数据传 说明:本文介绍app如何打开另一个app,并且传递数据. 一.简单说明 新建两个应用,分别为应用A和应用B. 实现要求:在appA的页面中点击对应的按钮,能够 ...

  10. Appcan 3.2 Switch操作

    Appcan3.0,有了很多不错的东西,但官方的文档还是那么的不靠谱. 我将记录下,我学习到的东西. 显示2个switch <div class="ub ub-pe"> ...