首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将多个参数传递给离子重排指令?

如何将多个参数传递给离子重排指令?
EN

Stack Overflow用户
提问于 2014-06-10 11:36:33
回答 1查看 1.2K关注 0票数 0

我把这个问题建立在以下代码基础上: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和一些基本代码部分:

代码语言:javascript
复制
directive("myitem", function() {
  return {
    restrict : "E",
    scope : {
      item : "=",
      onItemDelete : "&",
      moveItem : "&"
    },
    templateUrl : "MyItemTemplate"
  }
})

代码语言:javascript
复制
<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,我知道如何传递多个参数

但是,fromIndextoIndex没有被传播。

代码语言:javascript
复制
  $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);
  };

我试着查看源代码,移动到调用堆栈,但是我找不到任何明显的错误。

所以,是的,我真的很想从可重新排序的列表中获益,同时将它保存在一个单独的指令中。

EN

回答 1

Stack Overflow用户

发布于 2014-06-10 17:55:46

在本例中,要传递的参数的名称很重要。你想要:

代码语言:javascript
复制
 on-reorder="moveItem(item, $fromIndex, $toIndex)"
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24139967

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档