使用angularjs排序复选框列表

时间:2013-10-26 20:45:17

标签: angularjs angular-ui

有谁知道如何使用ui-sortable对复选框列表进行排序? 这是复选框列表:

<div class="controls">
    <label ng-repeat="player in playerlist">
        <input
                type="checkbox"
                name="player.firstname"
                ng-model="player.value"
                > {{player.firstname}}{{player.lastname}}
    </label>
    <!--<pre>{{playerlist| json}}</pre>-->
</div>

我已尝试(有点乐观地)将ui-sortable放入标签标签但没有运气......

有什么建议吗?

干杯,

kseudo

编辑*

抱歉....没有发布示例模型:)

playerlist = [
  {
    "firstname": "Mick",
    "lastname": "McCarthy",
    "_id": "5269409949e375aa0c000005",
    "__v": 0,
    "value": true
  },
  {
    "__v": 0,
    "_id": "5269408f49e375aa0c000004",
    "email": "kseudo@gmail.com",
    "firstname": "Brian",
    "lastname": "Cunningham",
    "phonenumber": 833069486,
    "value": true
  },
  {
    "firstname": "Bill",
    "lastname": "Bops",
    "phonenumber": 23456789,
    "email": "sdfsdf@werewr.iw",
    "_id": "526c011aaa6d6ef40c000003",
    "__v": 0,
    "value": true
  },
  {
    "firstname": "asdf",
    "lastname": "sdf",
    "phonenumber": 234,
    "email": "sdsdf@sdfsdf.ie",
    "_id": "526c01b4aa6d6ef40c000005",
    "__v": 0,
    "value": false
  }
]

1 个答案:

答案 0 :(得分:1)

你应该在div中添加ui-sortable而不是重复的标签本身。此外,您需要在其旁边包含ng-model指令,以便库知道要更新的模型。

<div class="controls" ui-sortable ng-model="playerList">

我还假设您在项目中包含了jQuery和jQueryUI。