在Array.map上返回undefined

时间:2016-08-24 09:54:54

标签: javascript arrays reactjs

我不希望这张地图返回未定义我该怎么做?

var onCompareSelectedClick = function () {
            var talentProfileInfoForAppliedResources = appliedResourcesEntries.map(function(res) {
                console.log(res);
                if(res.compareSelected == true) {
                    return data.getTalentProfileInfo(res.RES.RES_ID);
                }
            });
            console.log(talentProfileInfoForAppliedResources);
            this.openCompareTPDlg(talentProfileInfoForAppliedResources);
        }.bind(this);

1 个答案:

答案 0 :(得分:0)

只需在map方法中添加if(res.compareSelected == true) { return data.getTalentProfileInfo(res.RES.RES_ID); } else { return 'default_value'; } 语句,返回所需的值,例如:

<div class="w6">
  <div style="display: table; background-color: brown;">
    <div style="display: table-row" class="w12">
      <span class="w2" style="display: table-cell; background-color: blue;"></span>
      <!--<input type="text" class="w2"/>-->
      <span class="w10">
        <input type="text" />
      </span>
    </div>
  </div>
</div>