如题,绑定删除事件报错,其他没错,求教
<table class="table table-bordered" data-model="home"> <thead> <tr> <th>ID</th> <th> Name</th> <th>排序</th> <th>操作</th> </tr> </thead> <tbody data-bind="foreach:NavList"> <tr> <td data-bind="text:$data.ID"></td> <td data-bind="text:$data.Name"> <td data-bind="text:$data.Bid"></td> <td> <button class="btn btn-warning " data-bind="click:$data.removeList"> 删除</button> <button class="btn btn-primary cli" >修改</button> </td> </tr> </tbody> </table> <script> var home; $(function () { $.getJSON("@Url.Action("GetNavList", "Manger")",function (data) { home = function () { var self = this; self.NavList = ko.observable(data.data); self.count = ko.observable(data.total); //执行删除 self.removeList = function (stu) { console.info(stu); @*$.ajax({ url: "@Url.Action("Del", "Manger")" + stu.ID, type: "post", dataType: "json", success: function (json) { alert(json.type); self.NavList.remove(stu); self.count -= 1; } })*@ }; } ko.attach("home",home); }); }) </script>
这里是报错信息:
Uncaught Error: You cannot apply bindings multiple times to the same element.
at m (knockout-3.4.2.js:71)
at h (knockout-3.4.2.js:70)
at Object.a.Ub (knockout-3.4.2.js:76)
at HTMLTableElement.<anonymous> (knockout.multimodels-0.1.min.js:11)
at Function.each (jquery-1.10.2.min.js:25)
at init.each (jquery-1.10.2.min.js:25)
at d (knockout.multimodels-0.1.min.js:11)
at HTMLTableElement.<anonymous> (knockout.multimodels-0.1.min.js:11)
at HTMLTableElement.<anonymous> (jquery.livequery.js:126)
at Function.each (jquery-1.10.2.min.js:25)
还没开通博客,不能上传图片。
有大神嘛?
那是因为你applybinding
同一个元素多次造成的。
日志的第一行已经说了错误原因了:
You cannot apply bindings multiple times to the same element.