我编写了一个 jquery 插件,允许用户使用触摸或鼠标( kind of like this )来使用 ul。该插件可以很好地更新 DOM,但我不确定如何告诉 Angular“更新”模型绑定(bind)。具体来说,移动 li 后,我在 li 中的 ng-click 不会触发。我还想更新 $index 并告诉服务器新订单是什么。有什么想法吗?
HTML:
<ul class="unstyled" ng-sortable>
<li ng-repeat="item in list.Items">
{{item.QuantityType.Name}} {{item.Name}} {{index}}
<button class="close" ng-click="deleteItem($index)" aria-hidden="true">×</button></li></ul>
指令:
.directive('ngSortable', function () {
return {
link: function (scope, element) {
angular.element(element).draggableTouch({ onSortEndCallback: function () { scope.finishedSorting(); } });
}
};
})
编辑:添加了更多上下文的代码。
最佳答案
假设 ng-click="deleteItem($index)"
不起作用
我建议您传递 item
而不是 $index
所以将您的代码更改为
ng-click="deleteItem(item)"
您可以使用indexOf
函数查找数组中的元素索引
scope.list.Items.indexOf(item)
关于javascript - 在 Angularjs 中使用列表会破坏 ng-click,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20011978/