javascript Angular UI-Grid:在单元格模板中,如何从不同的字段/单元格访问值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30939978/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Angular UI-Grid: In a cell template, how to access the value from a different field/cell
提问by TonyGW
I've been trying to use the Angular UI-Grid plugin to render data tables, and I have the following example data:
我一直在尝试使用 Angular UI-Grid 插件来呈现数据表,我有以下示例数据:
var data = [
{"id" : 10, "name" : "Name 1", "city" : "San Francisco"},
{"id" : 12, "name" : "Name 2", "city" : "San Diego"},
{"id" : 20, "name" : "Name 3", "city" : "Santa Barbara"},
];
below is the columnDefs for gridOptions, in the name field, I need to create a hyperlink using ui-sref
下面是 gridOptions 的 columnDefs,在名称字段中,我需要使用 ui-sref 创建一个超链接
$scope.gridOptions.columnDefs = [
{field: 'id', displayName: 'ID'},
{field: 'name',
cellTemplate: '<div class="ui-grid-cell-contents tooltip-uigrid" title="{{COL_FIELD}}">' +
'<a ui-sref="main.placeDetail{{placeId: \'{{row.entity.id}}\' }}">{{COL_FIELD CUSTOM_FILTERS}}</a></div>'
},
{field: 'city', enableSorting: true}
];
The table is rendered fine except for the row.entity.idvalue. The values I get in the hyperlinks (inside the name column) are sequential: 1, 2, and 3, instead of 10, 12, and 20 as defined in the data array, however, the idvalues displayed in the IDcolumn is what I am expecting: 10, 12, and 20. I wonder how you would access the idfield value inside the namefield, and why are the idin the namecell are sequential?
除了row.entity.id值外,表格呈现良好。我在超链接中(在名称列内)获得的值是连续的:1、2 和 3,而不是数据数组中定义的 10、12 和 20 ,但是,ID列中显示的id值是什么我期待:10,12和20。我不知道你将如何访问ID字段值内部名称字段,为什么是ID的名称细胞的顺序?
采纳答案by c0bra
You shouldn't need to use curly braces in ui-sref
as you're already in a JS expression. Try this:
您不需要在 in 中使用花括号,ui-sref
因为您已经在 JS 表达式中。试试这个:
ui-sref="main.placeDetail({placeId: row.entity.id })"
ui-sref="main.placeDetail({placeId: row.entity.id })"