使用jQuery sortable重新排列表行会干扰Angular orderBy

时间:2015-11-12 22:51:48

标签: javascript jquery html angularjs jquery-ui

最初我在一个角度应用程序中有一个表,它将使用orderBy根据某列中的值对其行进行排序。如果单击表标题,它将更改orderBy参数并使用该列中的值作为条件来使用列表。

现在,我正在尝试使用jQuery让用户手动重新排列表中的行。但是,当它们在重新排列后单击表上的表头时,行将排序错误。我假设有些东西没有在角度方面更新它看不到,但我现在找不到任何明确的东西。

$('#game-table tbody').sortable({
   opacity: 0.5
});

<table id='game-table'>
  <thead>
       <th>
         <a class="sortable-link" ng-click="sortType = 'title; sortReverse = !sortReverse">  
         Titles
         </a>
       </th>
  </thead>
  <tbody>
       <tr class="game" ng-repeat="game in data | orderBy:sortType:sortReverse" style="cursor:move;">

1 个答案:

答案 0 :(得分:0)

jQuery和Angular之间的根本区别在于jQuery在DOM上运行,而Angular在原始数据上运行。当jQuery UI Sortable更新您的表行(通过用户交互)时,Angular对此一无所知。这打破了Angular数据与该数据的DOM表示之间的关联。

您可能会发现Angular UI Sortable directive on GitHub有用。该指令的目的是利用jQuery UI Sortable功能,同时镜像Angular数据中的相同更改。