【问题标题】:Angular UI Grid not updating directives in cellsAngular UI Grid 不更新单元格中的指令
【发布时间】:2016-02-16 23:01:22
【问题描述】:

我有一个包含指令的 ui 网格,该指令有一个独立的范围并根据一些逻辑更改它的模板。

问题在于,在排序时(以及在 PAGING 时),指令的“逻辑”似乎没有被正确地“重新评估”。

在具体示例中,最右边的列应该只看到一些“11”,而如果您尝试按 id(或其他字段)排序,您会看到一些虚假的“0”出现。

这是用户界面:

<div ng-app="myapp">
  <div ng-controller="myctrl">
    <div ui-grid="gridOptions" ng-style="gridStyle"></div>
  </div>
</div>

这是js:

var myapp = angular.module('myapp', ["ngRoute", "ui.grid"])

.controller('myctrl', function($scope) {

  $scope.gridOptions = {
    data: [{
      id: 1,
      name: "Max",
      other: "pippo",
      number: 1
    }, {
      id: 2,
      name: "Adam",
      other: "pluto",
      number: 0
    }, {
      id: 3,
      name: "Betty",
      other: "paperino",
      number: 0
    }, {
      id: 4,
      name: "Sara",
      other: "fava",
      number: 1
    }, {
      id: 5,
      name: "Favonio",
      other: "favona",
      number: 1
    }],
    columnDefs: [{
      field: "id",
      displayName: "ID"
    }, {
      field: "name",
      displayName: "Name"
    }, {
      field: "other",
      displayName: "Other"
    }, {
      field: "number",
      cellTemplate: '<div class="ui-grid-cell-contents"><mydir data="row.entity"></mydir></div>'
    }]
  };

}).directive("mydir", function() {
  return {
    restrict: 'E',
    scope: {
      data: "=",
    },
    template: '<div><label ng-if="data.number==1">{{set}}</label></div>',
    link: function(scope, iElement, iAttrs) {

      scope.set = -1;

      if (scope.data.number == 0) {
        scope.set = 00;
      } else {
        scope.set = 11;
      }

    }
  }
});

这是一个小提琴:

https://jsfiddle.net/27yrut4n/

有什么提示吗?

【问题讨论】:

    标签: angular-ui-grid


    【解决方案1】:

    最后这是一个已知的错误:

    https://github.com/angular-ui/ui-grid/issues/4869

    我使用手表解决了,就像这里所说的那样:

    Directive rendered via UI-Grid cellTemplate rendering incorrectly

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-16
      • 2019-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-28
      相关资源
      最近更新 更多