鍍金池/ 問答/HTML5  HTML/ react+antd 如何判斷columns當中存不存在某個dataindex。

react+antd 如何判斷columns當中存不存在某個dataindex。

const columns = [

{
    dataIndex: 'hphm',
    title: '車牌號碼'
},
{
    dataIndex: 'Excdmc',
    title: '出口通道'
}
,
{
    dataIndex: 'gxsj',
    title: '取消時間'
}
,
{
    dataIndex: 'Admin_name',
    title: '取消人'
}

]
以上就是columns , 比如現(xiàn)在如何判斷columns中存不存在一個'hphm'的dataindex,有沒有較直接的方式。

回答
編輯回答
浪婳

你可以使用數(shù)組的 .find() 方法

const target = column.find(item => item.dataIndex === 'hphm')

如果 target 不為 undefined 的話就是有的

2018年2月19日 02:26
編輯回答
萌吟
if(/\"dataIndex\"\:\"hphm\"/.test(JSON.stringify(columns))) {
    // 存在
} else {
    // 不存在
}
2017年7月27日 14:37
編輯回答
陌顏
if(columns.some(col => col.dataIndex === 'hphm')) {
    //存在
}
2017年6月23日 21:26