对不起这个noobish问题。我觉得必须有更好的方法,但我没有看到它。我不想在按钮单击中循环查找 ID。我只想传递要删除的索引。
这就是我认为我必须做的事情
html
<div id="list">
{^{for items}}
<div class="list-item">
...
<a href="#" class="remove-list-item">Remove
<span class="remove-list-item-index hide">{^{:#index}}</span>
</a>
</div>
{{/for}}
</div>
js
$('a.remove-list-item').click(function () {
$.observable(listArray).remove(parseInt($(this).children('span.remove-list-item-index').text()));
});
这就是我想做的
html
<div id="listing">
{^{for items}}
<div class="listing-item">
...
<a href="#" data-index="{^{:#index}}">Remove</a>
</div>
{{/for}}
</div>
js
$('a.remove-list-item').click(function () {
$.observable(listArray).remove(parseInt($(this).attr('data-index')));
});