【问题标题】:Ng-repeat did not update rows after manual manipulation?手动操作后 Ng-repeat 没有更新行?
【发布时间】:2014-02-17 12:16:52
【问题描述】:

我有一个 ng-repeat 工作正常。我应用了一个也可以正常工作的 x-editable。有很多页,应用了分页。我正在使用 ng-table。然而,当使用 jquery x-editabe(通过其 ajax 方法)更新某些记录时,angularjs、ng-repeat 停止更新该特定的 .为什么?

 <td title="'Price'" data-type="number" my-x-editable data-sortable="'Price'" filter="
        {'Price':'text'}">{{product.Price}}
 </td>
  <td title="'Vendor'" data-sortable="'Vendor'" filter="{'Price':'text'}">
                    <a href="#" id="VendorID"  class ="xEditable" data-type="select" data-pk="{{product.ID}}" data-source='@Url.Action("ProductVendors")' data-value="{{product.Vendor.ID}}" data-url ="@Url.Action("UpdateAttributes")" title ="@Resources.OA_Attribute_Vendor">{{product.Vendor.Name}}</a>
  </td>

如果我不使用 x-editable 进行更新,一切都会正常运行。当我使用 x-editable 时,当我转到下一页时,该特定列不会用 ng-repeat 更新。

【问题讨论】:

  • 这里的问题是你在 Angular 之外操作一个作用域属性。 Angular 理解更改是基于运行 $digest 并进行脏检查而做出的。因此,如果外部库正在更改数据,Angular 将不会知道。

标签: javascript jquery angularjs angularjs-ng-repeat x-editable


【解决方案1】:

对于在 AngularJS 之外完成的任何更改(如 DOM 操作等),需要调用 $apply 以便 AngularJS 可以选择并将这些更改反映在视图上。

这是一个有用的链接:http://jimhoskins.com/2012/12/17/angularjs-and-apply.html

【讨论】:

    【解决方案2】:

    您需要调用 $scope.$apply 以便 Angular 了解在 Angular 自身上下文之外所做的更改。

    【讨论】:

      猜你喜欢
      • 2018-04-15
      • 1970-01-01
      • 2017-02-15
      • 2015-03-02
      • 2016-04-20
      • 1970-01-01
      • 2015-01-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多