首页 > 解决方案 > 实时数据绑定

问题描述

我有一个显示上传文件列表的表格。如果我上传了一个文件,它需要反映在表格中。这已经在发生了——然而,不是实时的。我需要刷新页面以反映我需要的数据。

我尝试在 jquery 中刷新 div 但它不起作用:

<div class="mjs-cell">
            <div id="stipsData" data-bind="template:{name: 'rehash-customertab-stips-section', data: stipsViewModel}">
            </div>
        </div>

<div class="mjs-row">
        <table class="table table-striped table-bordered">
            <tr>
                <th>Stip Name</th>
                <th>Status</th>
                <th>File Name</th>
            </tr>
            <tbody data-bind="foreach: $data">
                <tr class="stips-row">
                    <td class="hidden stips-id" data-bind="text: StipulationTypeId"></td>
                    <td class="stips-text">
                        <a data-bind="text: StipulationType"></a>
                    </td>
                    <td class="stips-status">
                        <span data-bind="text: Status"></span>
                    </td>
                    <td class="stips-uploaded-file" data-bind="text: FileName"></td>
                </tr>
            </tbody>
        </table>
    </div>

这是我用于绑定的代码:

  stipsViewModel = ko.computed(function () {
            DealApiControllers.GetStipulations(dealId,
                (response) => {
                    this.stipsViewModel = response.DealStipulationsDTOs;
                },
                (error) => {
                    console.error(error);
                });
        }, this);

例如,该表显示 Doc1、Doc2。如果我上传 Doc3,它应该会反映在列表中。

标签: data-bindingknockout.js

解决方案


推荐阅读