我把这个问题建立在以下代码基础上:http://codepen.io/ionic/pen/JsHjf
它使用:<ion-reorder-button class="ion-navicon" on-reoder="moveItem(item, fromIndex, toIndex)"></ion-reorder-button>,它运行得很好。
我想把整个<ion-item>变成一个指令。下面是我的plnkr:http://plnkr.co/edit/w61yqfuCypliugToUD3E?p=preview和一些基本代码部分:
directive("myitem", function() {
return {
restrict : "E",
scope : {
item : "=",
onItemDelete : "&",
moveItem : "&"
},
templateUrl : "MyItemTemplate"
}
})
<ion-item>
{{ item.id }}
<ion-delete-button class="ion-minus-circled" ng-click="onItemDelete({'item': item})"></ion-delete-button>
<ion-reorder-button class="ion-navicon" on-reorder="moveItem({'item' : item, 'fromIndex' : fromIndex, 'toIndex' : toIndex})"></ion-reorder-button>
</ion-item>
由于这个问题:AngularJS directive binding a function with multiple arguments,我知道如何传递多个参数
但是,fromIndex和toIndex没有被传播。
$scope.moveItem = function(item, fromIndex, toIndex) {
console.log("moveItem: ", item, fromIndex, toIndex);
console.log("unfortunately, the fromIndex and toIndex are undefined");
$scope.items.splice(fromIndex, 1);
$scope.items.splice(toIndex, 0, item);
};我试着查看源代码,移动到调用堆栈,但是我找不到任何明显的错误。

所以,是的,我真的很想从可重新排序的列表中获益,同时将它保存在一个单独的指令中。
发布于 2014-06-10 17:55:46
在本例中,要传递的参数的名称很重要。你想要:
on-reorder="moveItem(item, $fromIndex, $toIndex)"https://stackoverflow.com/questions/24139967
复制相似问题