arrays - 如何以具有字段值的角度返回嵌套对象数组的特定字段?
问题描述
我有一个像这样的嵌套对象数组。
这是我的数组:
public collections: ICollections[] = [
{
collectionName: 'Brands',
collectionFields: [
{
columnTitle : 'brandTitle',
Type : dtEnum.string,
control: {
controlTitle: controlsEnum.input,
controlType: controlsEnum.input,
controlProperties:
{
placeholder: 'Enter brand title here ...',
type: 'text',
autocomplete: false,
}
},
columnWidth: 200
}
],
collectionFieldValidation: [{name: 'test'}],
hasPaginator: true,
stickyColumn: 0,
stickyHeader: true
},
{
columnTitle : 'brandURL',
Type : dtEnum.string,
control: {
controlTitle: controlsEnum.input,
controlType: controlsEnum.input,
controlProperties: {
placeHolder: 'Enter Brand URL',
type: 'text',
autocomplete: false,
}
},
columnWidth: 300
},
{
columnTitle : 'brandDescription',
Type : dtEnum.string,
control: {
controlTitle: controlsEnum.textarea,
controlType: controlsEnum.textarea,
controlProperties: {
placeHolder: 'Enter Brand Description',
type: 'text',
autocomplete: false,
}
},
columnWidth: 300
}
];
我想到达placeholder
外地。我如何通过只有collectionName
带有Brands
value的columnTitle
字段和带有brandURL
value 的字段来找到它?
这个问题之前只是用collectionName
字段值提出的,但我发现我的过滤器应该包含多个字段。
解决方案
首先,找到与“品牌”或任何其他东西相对应的集合:
let result = collections.find(p => p.collectionName === "Brands");
然后获取placeholder
字段:
更改your_index
为 0 或您的特定索引
if (result) {
let placeholder = result.collectionFields[your_index].control.controlProperties.placeholder;
}
推荐阅读
- wpf - 不依赖于 MainWindow 的 DialogService
- sql-server - SQL Server 合并复制 - 快照重新应用时订阅者数据丢失以解决错误
- java - 如何在jpa中加入具有多个主键或特定主键的列
- visual-studio-code - VSCode 启动 wsl.exe 进程,这些进程在 VSCode 关闭后不会终止
- reactjs - 从数据库获取数据以在 getStaticMap 方法 Next.js 中设置动态路线
- kubernetes - Google Kubernetes Api Cron 作业
- php - 在 Laravel 对象集合上使用搜索功能来返回键?
- docker-compose - docker-compose 卷挂载它在 Windows 中不起作用?
- javascript - 如何将 2 个图表并排放置
- javascript - 您可以使用 JavaScript 定位浏览器自动填充功能吗?