data.downlinkmoons =[{Lion: 237, birds: "Animal Sports Bay Area", fish: 1, isDefault: true, wire: ""},
{Lion: 238, birds: "Animal Sports California", fish: 1, wire: ""},
{Lion: 239, birds: "Animal Sports Washington", fish: 1, wire: ""},
{Lion: 240, birds: "Animal Sports Philadelphia", fish: 1, wire: ""}]
playOutside(data: any) {
let that = this;
let tempObj = {};
//tempObj['Lion'] = 237;
tempObj['Lion'] = data.downlinkmoons[0].Lion;
tempObj['birds'] = 'Animal Sports Bay Area';
// tempObj['Lion'] = data.selectedLion;
// tempObj['birds'] = data.selectedbirds;
this.moonTempArray = [];
this.moonTempArray.push(tempObj);
let moonsdata = data.downlinkmoons;
let moonsDataList = this.moonTempArray;
let selectedmoon = moonsdata.find(elem => elem.Lion == 237);
this.downlinkBulkUpdateVal.Lion = 237;
// let selectedmoon = moonsdata.find(elem => elem.Lion == data.selectedLion);
// this.bulkCreateVal.Lion = data.selectedLion;
this.selectedmoonArr = selectedmoon;
this.moonCarousel.setmoonData(moonsdata, moonsDataList, 237);
//this.moonCarousel.setmoonData(moonsdata, moonsDataList, data.selectedLion);
$("#moonCarouselLabel .moonHint").css("display", "none");
setTimeout(function () {
$("#unSelectedmoonsLogoBox1 .currentNwLogo").bind("click", function (e) {
e.stopPropagation();
that.singleSelection(data, e);
});
}, 100);
}
答案 0 :(得分:1)
您可以使用Array.prototype.find()
功能:
var downlinkmoons =[{Lion: 237, birds: "Animal Sports Bay Area", fish: 1, isDefault: true, wire: ""},
{Lion: 238, birds: "Animal Sports California", fish: 1, wire: ""},
{Lion: 239, birds: "Animal Sports Washington", fish: 1, wire: ""},
{Lion: 240, birds: "Animal Sports Philadelphia", fish: 1, wire: ""}];
function getDefault(downlinkmoons){
return downlinkmoons.find((elem) => { return elem.isDefault; });
}
console.log(getDefault(downlinkmoons))
有关Array.prototype.find的更多信息,请here。
答案 1 :(得分:0)
这是
var downlinkmoons =[{Lion: 237, birds: "Animal Sports Bay Area", fish: 1, isDefault: true, wire: ""},
{Lion: 238, birds: "Animal Sports California", fish: 1, wire: ""},
{Lion: 239, birds: "Animal Sports Washington", fish: 1, wire: ""},
{Lion: 240, birds: "Animal Sports Philadelphia", fish: 1, wire: ""}];
function getDefault(downlinkmoons){
for(var i=0; i<downlinkmoons.length; i++){
if(downlinkmoons[i].hasOwnProperty("isDefault"))
{
if(downlinkmoons[i].isDefault)
return downlinkmoons[i];
break;
}
}
}
console.log(getDefault(downlinkmoons))
在脚本中使用它请执行以下操作
tempObj['Lion'] = getDefault(downlinkmoons).Lion