无文本表格,Net6 + Knockout.js + DataTables.net

c3frrgcw  于 2022-11-10  发布在  .NET
关注(0)|答案(1)|浏览(126)

当页面加载时,请填写以下内容:

<select class="form-control" 
        data-bind="options: UsersList,
                optionsText: function(item) {
                    return item.name()
                },
                value: selectedUser"></select>

然后选择其中一个用户并

self.loadADGroups = () => {
        self.selectedUser().ActiveDirectoryUserGroupList.removeAll();
        let getParams = {
            distinguishedName: self.selectedUser().ident()
        };

        $.ajax({
            method: 'GET',
            url: ActiveDirectoryGroupsListUrl,
            data: getParams,
            success: (responseData) => {
                responseData.forEach((o, i, a) => {
                    var vm = getActiveDirectoryGroupViewModel(o);
                    self.selectedUser().ActiveDirectoryUserGroupList.push(vm);
                });
            },
            error: () => {
            }
        });
    }

Html表格:

<div id="ReportActiveDirectoryGroupUser" data-bind="with: selectedUser() ">
    <table id="ReportTableActiveDirectoryGroupUser"  style="width:100%">
        <thead>
            <tr>
                <th>Nazwa grupy w AD</th>
                <th>Opis grupy w AD</th>
            </tr>
        </thead>
        <tbody data-bind="foreach: ActiveDirectoryUserGroupList">
            <tr>
                <td><span data-bind="text: AdName"></span></td>
                <td><span data-bind="text: Addecsription"></span></td>
            </tr>
        </tbody>
    </table>

</div>

该表的行数与从控制器返回的模型的行数相同,但其中没有数据,而模型中有

dba5bblo

dba5bblo1#

返回模型有AdNameAdDescription-但是在responsedata中,有adNameadDescription.

getActiveDirectoryGroupViewModel = (apiResponseObject) => {
    var result = new ActiveDirectoryGroupViewModel();

    result.AdName(apiResponseObject.adName);
    result.Addecsription(apiResponseObject.addecsription);

    return result;
}

这个工作。

相关问题