AngularJSを採用したアプリケーションで、ui-sortableを使った要素の並び替えと保存をしようとしています。リファレンスを読みつつ並び替え後の順番を出力させるところまで実装したのですが、データを保存するとことが自信がないのでご教授ください。
以下のようにfromとtoを用意し、iの個数分だけwhileでループを回しています。このような書き方で問題ないでしょうか。一応、意図している動作は行われているかと思うのですが書き方に自信がありません... このままで問題ないでしょうか?そもそもwhileなど使わない方法でもっと良い書き方などありますでしょうか?よろしくお願いいたします。
= = =
《controller》
javascript
1tmpList = [] 2i = 1 3while i <= 7 4 tmpList.push 5 text: 'Item ' + i 6 value: i 7 i++ 8$scope.list = tmpList 9$scope.sortableOptions = 10 stop: (e, ui) -> 11 from = 0 12 to = i - 2 13 while from <= to 14 $scope.newList = { text: tmpList[from].text, order: tmpList[from].value } 15 Item.update($scope.newList) 16 console.debug $scope.newList 17 from++ 18 return 19return
《view》
html
1<ul ui-sortable="sortableOptions" ng-model="list"> 2 <li ng-repeat="item in list">{{item.text}}</li> 3</ul>
あなたの回答
tips
プレビュー