我有一个页面,将 View 模型绑定(bind)到 jQuery UI 对话框内的 HTML 表。
当用户关闭对话框时,我想删除 viewmodel observableArray
中绑定(bind)到 HTML 表的所有元素。我正在使用 removeAll()
方法,但我的 Firebug 告诉我该方法未被识别为函数。
你能帮我吗?
这是一个简化的场景。
HTML
<input type="button" id="open" value="GO!"><br />
<div id='hidden'>
<table>
<tbody data-bind="foreach: i">
<tr>
<td><span data-bind="text: code" /></td>
<td><span data-bind="text: descr" /></td>
</tr>
</tbody>
</table>
</div>
JS
$(function () {
function vm() {
this.items = [
{code: "2011",descr: "descr 2011"},
{code: "2012",descr: "descr 2012"},
{code: "2013",descr: "descr 2013"}
];
this.i = ko.observableArray(this.items);
this.clearFoundEvals = function()
{
this.i.removeAll();
};
return this;
}
ko.applyBindings(new vm());
$dialog = $('#hidden').dialog({
autoOpen: false,
height: 200,
width: 300,
buttons: {
cancel: function () {
vm.clearFoundEvals();
$(this).dialog('close');
}
}
});
$('#open').click(function(){
$dialog.dialog('open');
});
});
最佳答案
关于javascript - knockout removeAll()无法识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15022764/