【发布时间】:2015-01-22 15:19:54
【问题描述】:
我正在编写一些 jQuery 代码,但我有一些疑问。这是我到现在为止的:
var html = '';
data.entities.forEach(function (value, index, array) {
html += index !== data.entities.length-1 ? value.pais + ', ' : value.pais;
});
var rowUpdate = $('#distribuidorBody').find('#td-' + data.idToUpdate);
rowUpdate.text() !== "" ? html += ', ' + html : html;
rowUpdate.append(html);
大想法:我可以多次执行相同的代码,所以第一次 rowUpdate 没有任何值,所以 text() 是空的,我会得到一些 HTML 输出,例如:Country1, Country2, Country3 和依此类推,然后rowUpdate.text() 应该是Country1, Country2, Country3。因此,如果我第二次运行相同的代码并添加Country4, Country5,那么rowUpdate.text() 应该是Country1, Country2, Country3, Country4, Country5。我的代码对吗?如果没有任何帮助?我没有收到错误,但我需要了解我所做的是对还是错。我也想知道这段代码的作用:
rowUpdate.text() !== "" ?: html += ', ' + html;
它不是我的,我在它周围看到它,但不知道它的作用。
【问题讨论】:
标签: javascript jquery html