gpt4 book ai didi

javascript - 如何使用 UI Grid 自定义字段的输出

转载 作者:行者123 更新时间:2023-12-03 10:23:49 25 4
gpt4 key购买 nike

我有一组字段或每行看起来像{inBing:true, inOSM:true, inGoogle:false}。根据这些,我想将这些值表示为字符串,例如“B O”,这意味着 Bing 和 OSM 已启用,而 Google 未启用。

所以我需要遍历这些字段并构建一个输出字符串。

问题是我可以在UI grid中的哪里放置和调用这个函数?

最佳答案

我会为此使用过滤器。

处理您的数据,使其看起来像:

{ field1: value1, field2: value2, searchFlags: { inBing: true, inOSM: false, inGoogle: true } }
{ field1: value2, field2: value4, searchFlags: { inBing: false, inOSM: true, inGoogle: false } }
...

你的columnDefs如下:

columnDefs: [
{ name: 'field1' },
{ name: 'field2' },
{ name: 'searchFlags', cellFilter: 'mapFlags' }
];

最后,定义过滤器:

.filter('mapFlags', function( input ) {
str = '';
if (v.inBing) str += 'B ';
if (v.inOSM) str += 'O ';
if (v.inGoogle) str += 'G';
return str;
});

http://ui-grid.info/docs/#/tutorial/201_editable中有一个过滤器的例子

关于javascript - 如何使用 UI Grid 自定义字段的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29501365/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com