2017-08-27 58 views
0

我需要列出的對象和搜索需要用逗號分隔的字符串。我已經添加了以下forEach方法,我想知道是否有任何單線解決方案。更好的解決方案搜索除了forEach

this.props.items.map((item, key) => (
     this.props.campaign_name.split(",").forEach(function(entry) { 
       (item.campaign_name.toLowerCase().indexOf(entry.toLowerCase()) )?true:false 
     }.bind(this)) 

)) 
+0

你曾經嘗試過使用lodash? –

+1

你有的代碼沒有做任何有用的事情。你爲什麼在這裏使用'.bind(this)'? –

回答

0

你不能使用過濾器this.props.campaign_name.split(",").filter(entry => item.campaign_name.toLowerCase().indexOf(entry.toLowerCase()) !== -1)