我可能遗漏了一些非常简单的东西,但谁能指出我在这里做错了什么?
提前谢谢了。
<div data-bind="foreach: agencies">
<div data-bind="text:name"></div>
<div data-bind="text:email"></div>
<button data-bind="click: removeAgency">remove</button>
</div>
<script type="text/javascript">
var agency = [{
name : ko.observable('a'),
email : ko.observable('b')
}, {
name: ko.observable('c'),
email: ko.observable('d')
}];
var vm = {
agencies: ko.observableArray(agency),
removeAgency: function(agency) {
this.agencies.remove(agency);
}
};
ko.applyBindings(vm);
</script>
这是我得到的错误:未捕获的错误:无法解析绑定。消息:ReferenceError:removeAgency 未定义;绑定值:点击:removeAgency