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

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);

最佳答案

只需在else方法内添加map语句即可返回所需的值,例如:

if(res.compareSelected == true) {
   return data.getTalentProfileInfo(res.RES.RES_ID);
} else {
   return 'default_value';
}

10-02 04:51