在 Angular UI-Grid 中检测 ui-grid 值

Detect ui-grid value within Angular UI-Grid

那是我的网格

<div
    ui-grid="myAPI.myGrid"
    ui-grid-pinning
    ui-grid-pagination
    ui-grid-resize-columns
    class="gridMid">
</div>

如何检测网格内的 "myAPI.myGrid"

(点击 row/column/cell/button/whatever/.. 应该例如提醒 "myAPI.myGrid"

ui-grid 指令属性的值称为 gridOptions,您可以直接从 grid 对象中检索 options 属性:grid.options.

您可以在自定义模板中完美地使用网格对象,只需参考它,如tutorial:

中所述

In the cellTemplate you have access to grid, row and column, which allows you to write any of a range of functions.

所以只需在模板中调用 grid.options 即可,如果需要获取数据数组,只需使用 grid.options.data

如果您需要在其他地方获取对 grid 对象的引用,您可以从 gridApi 对象中获取它(查看 here 以获取有关 gridApi 的更多信息)只需使用 gridApi.grid

编辑:添加了 plunker 和说明。

我构建了 a plunker,我将对象传递给控制器​​范围内的 clickFn,只需单击最后一列中的任何单元格。

请注意,当我在对你的问题的评论中谈到网格的名称时,我是非常不准确的:没有像网格名称这样的概念,但是,正如我之前在这个答案中所说的那样,你所说的 myApi.myGrid 只是对对象的引用,因此您只能 pass/retrieve 该对象,而不是您为该引用指定的名称。

我想这不是问题,因为您最终需要的是对象。如果你想检查它,只需在我的 plunkr.

中的 clickFn 内放置一个断点。

编辑:添加了新插件

我创建了一个 new plunkr,其中 clickFn 函数的行为类似于 "Delete" 按钮。