【发布时间】:2014-08-29 07:10:49
【问题描述】:
我有一个 <table> 和一个 <td>,我想在其中替换文本 - 使用 javascript。
<table class="table">
<tbody>
<tr>
<td id="53ffaf3e436872c452020000">
2014-08-16T11:00:00.000+02:00
</td>
</tr>
</tbody>
</table>
我从服务器收到一个 key/value 循环的 new_dates 对象:
咖啡脚本版本:
last_dates.map (last_date) ->
for key of last_date
console.log key + " has the date: " + last_date[key] # 53ffb262436872c499b90f00 has the date: 2014-08-16T11:00:55.000+02:00
$("##{key}").text = "#{last_date[key]}"
Javascript 版本:
last_dates.map(function(last_date) {
var key, _results;
_results = [];
for (key in last_date) {
console.log(key + " has the date: " + last_date[key]); // 53ffb262436872c499b90f00 has the date: 2014-08-16T11:00:55.000+02:00
_results.push($("#" + key).text = "" + last_date[key]);
}
return _results;
});
上面的代码应该从key's 中找到所有id's,并将它们的文本值替换为value's。但是,我的代码不起作用。我做错了什么?
【问题讨论】:
标签: javascript jquery html coffeescript