我在显示推送到数据库的 JSON 存储数据时遇到问题。这是我的代码片段,用于显示推送到服务器的 json 存储文档。
var _showTable = function (arr) {
if (_.isArray(arr) && arr.length < 1) {
return _logMessage(EMPTY_TABLE_MSG);
}
//Log to the console
WL.Logger.ctx({stringify: true, pretty: true}).info(arr);
var
//Get reference to the status field
status = $('div#status-field'),
//Table HTML template
table = ['<table id="bu_table" >',
'<tr>',
'<td><b>JSON ID</b></td>',
'<td><b>BU NAME</b></td>',
'<td><b>BU DESC</b></td>',
'</tr>',
'<% _.each(bu, function(results) { %>',
'<tr>',
'<td> <%= results._id %> </td>',
'<td> <%= results.json.buname %> </td>',
'<td> <%= results.json.budesc %> </td>',
'</tr>',
'<% }); %>',
'</table>'
].join(''),
//Populate the HTML template with content
html = _.template(table, {bu : arr});
//Put the generated HTML table into the DOM
status.html(html);
};
我正在尝试通过单击按钮来显示数据库中的文档。每次单击按钮时,整个文档都会附加到表格中,而不是替换。每次单击按钮时,如何替换文档而不是重复?