angularjs - ng-repeat does not seem to rebind ng-click on a re-rendering -


i have ng-repeat assigned row in table shown below. when user selects down arrow in row, method movedown gets executed, reorders list (see code).

when @ dom, looks right - rows reordered, , ng-click sees newly assigned seqnbr.

better explanation:

initially first row shows data-ng-click='movedown(0);' second data-ng-click='movedown(1);'

after selecting first one, first , second row trade places. seqnbr swapped in objects , list reordered, ng-repeate reexecuted.

now dom shows new first row has: data-ng-click='movedown(0);' , old first row, second row, has data-ng-click='movedown(1);'

however if select new first row, gets executed movedown(1) (the old method associated row). if dom updated, not method binding.

html:

    <tr class='evidencerow' data-ng-repeat="e in data.evidence">         <td><div class='assertion webdiv' style='height:4em;'                  data-ng-dblclick='openreference(e);'>                 <span data-ng-bind-html-unsafe='e.assertion'></span>             </div>         </td>         <td>             <img src='img/uparrow16x16.png' data-ng-hide='$first'                          data-ng-click='moveup({{e.seqnbr}});' style='width:32px;'>             <img src='img/downarrow16x16.png' data-ng-hide='$last'                          data-ng-click='movedown({{e.seqnbr}});' style='width:32px;'>         </td>     </tr> 

controller code:

$scope.moveup = function(seq) {     var recs = $scope.data.evidence.slice(0);     recs[seq].seqnbr = seq - 1;     if (_ev.notempty(recs[seq - 1])) {         var s2 = seq - 1;         recs[s2].seqnbr = seq;     }     recs.sort(_ev.compareseqnbr);     $scope.data.evidence = recs; };  $scope.movedown = function(seq) {     var recs = $scope.data.evidence.slice(0);     recs[seq].seqnbr = seq + 1;     if (_ev.notempty(recs[seq + 1])) {         var s2 = seq +1;         recs[s2].seqnbr = seq;     }     recs.sort(_ev.compareseqnbr);     $scope.data.evidence = recs; }; 

this behavior doesn't seem right me. result instead of rows moving , down, toggle , forth.

try out this jsfiddle. think you're looking for.

i modified moveup() , movedown() functions bit , take full "evidence" object rather number.

$scope.moveup = function(e) {     var idx = $scope.data.evidence.indexof(e);     var removed = $scope.data.evidence.splice(idx, 1);         $scope.data.evidence.splice(idx - 1, 0, removed[0]); };  $scope.movedown = function(e) {     var idx = $scope.data.evidence.indexof(e);     var removed = $scope.data.evidence.splice(idx, 1);         $scope.data.evidence.splice(idx + 1, 0, removed[0]); };  

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -