javascript - 与 Bootstrap 表内的嵌套循环进行淘汰赛绑定(bind)

标签 javascript jquery twitter-bootstrap model-view-controller knockout-2.0

Result after binding the value using knockout

上图显示了数据与knockout数组绑定(bind)后的结果。然而预期的结果并不是这样的。我想要如图所示的以下结果

enter image description here

HTML 代码

<table class="table tableMini top10">
    <thead>
        <tr>
            <th>Workflow</th>
            <th style="width:190px;">Access</th>

        </tr>
    </thead>
    <tbody data-bind="foreach: Access_label">
        <tr>
            <td data-bind="text: $data.Application">
                <strong/>
            </td>
            <td>
                <input type="checkbox">
                </td>
            </tr>


            <tr>
                <td>
                    <table class="table tableMini top10">
                        <tbody data-bind="foreach: $data.ListAccessRights">
                            <tr>
                                <td data-bind="text: $data.Name">
                                    <span class="l45"/>
                                </td>
                                <td>
                                    <input type="checkbox">
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </td>


                </tr>
            </tbody>
        </table>

Json Result

上图显示了服务器的响应

淘汰js代码

GetRoleList: function () {
        var self = this
        $.ajax({
            type: "GET",
            url: '/Employee/GetRoleList',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            async: false,
            success: function (data) {
                self.RoleList(data.Roles);
                self.Roles_Type_list(data.RoleType);
                self.Campaign_Type_list(data.CampaignType);
                self.Access_label(data.AccessRight);
            },
            error: function (err) {

                alert(err.status + " : " + err.statusText);

            }
        });


    }

我想知道如何执行循环以便获得想要的结果

最佳答案

我会这样做:

<table class="table tableMini top10">
    <thead>
        <tr>
            <th>Workflow</th>
            <th style="width:190px;">Access</th>
        </tr>
    </thead>
    <tbody data-bind="foreach: Access_label">
        <tr>
            <td>
                <strong data-bind="text: Application"></strong>
            </td>
            <td>
                <input type="checkbox"/>
            </td>
        </tr>
        <!-- ko foreach: ListAccessRights -->
        <tr>
            <td class="l45" data-bind="text: Name"></td>
            <td>
                <input type="checkbox"/>
            </td>
        </tr>
        <!-- /ko -->
    </tbody>
</table>

关于javascript - 与 Bootstrap 表内的嵌套循环进行淘汰赛绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30915202/

相关文章:

javascript - 使用 jQuery 加载时淡入页面背景图像

c# - 正则表达式查找 html 标签后缺失的空格

css - 使用 bootstrap 或 css 居中 ul 内容

javascript - Jquery animate() 效果不能很好地发挥作用

javascript - 价格计算 - Javascript

jquery - 带 Bootstrap 的幻灯片放映

html - 覆盖 Bootstrap 默认值 !important 颜色代码

javascript - 检测浏览器中已安装的扩展?

javascript - 如何将代码隐藏信息传递到 JavaScript 函数中

javascript - 使用 David J Bradshaw 的 iframe-resizer