通过 UI-Grid cellTemplate 渲染错误的指令 [英] Directive rendered via UI-Grid cellTemplate rendering incorrectly

查看:20
本文介绍了通过 UI-Grid cellTemplate 渲染错误的指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个奇怪的问题,因为我的指令似乎在过时的 row.entities 上执行,这意味着当您向下滚动或修改网格类型时,它不会获得新值.最初的 ~20 行呈现良好,但过了之后指令与行分离.

I am experiencing a strange issue in that my directive seems to be executing on stale row.entities, meaning it does not get the new values as you scroll down or modify the sort of the grid. The initial ~20 rows render fine but past that the directives become disassociated with the rows.

请在此处查看我的黑客攻击示例.

See my very hacked together example here.

推荐答案

看起来在您传递给指令的表达式的排序值期间发生了变化,但表达式本身保持不变.

It looks like during sort values of the expression you pass to directive change, but the expression itself stays the same.

您应该将范围 & 表达式绑定更改为 = 值绑定(并使用 scope.installs 访问值,无需函数调用),然后您将能够跟踪更改.

You should change scope & expression binding to = value binding (and access the value with scope.installs, without function call), then you will be able to track the changes.

// ...
scope: {
  installs: '='
},
// ...

然后,要跟踪更改,您可以使用 scope.$watch 并将代码放入其中.

Then, to track the changes you can use scope.$watch and put your code inside.

link: function (scope, element, attrs) {
  scope.$watch('installs', function(newValue) {
    // your code, you can use newValue as current installs value
    var installs = newValue;
    // ...
  });
}

示例此处.

这篇关于通过 UI-Grid cellTemplate 渲染错误的指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆