data-binding - 实时数据绑定
问题描述
我有一个显示上传文件列表的表格。如果我上传了一个文件,它需要反映在表格中。这已经在发生了——然而,不是实时的。我需要刷新页面以反映我需要的数据。
我尝试在 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,它应该会反映在列表中。
解决方案
推荐阅读
- javascript - 我可以绕过可选参数并仍然在 Javascript 中设置休息参数吗?
- java - Java 无法从 Db2 数据库中读取中文字符
- postgresql - 将 Ruby on Rails 应用程序迁移到 Docker:Docker-Compose 的问题
- google-apps-script - 无法列出所有群组电子邮件的用户(谷歌应用脚本)
- html - 使用 html/css 在移动设备上堆叠带有图像的表格
- microsoft-edge - 禁用 Microsoft Edge 的 HTTP2
- git - GIT输入了错误的密码,不能再克隆了
- java - 将行添加到表后,无法更改 .docx 文件中的行文本
- ajax - 如何让控制器将投票值注册到数据库?
- excel-2010 - 如果单元格中有日期,则返回日期;如果单元格为空白或有文本,则返回 N/A 或空白