如何将数组中的元素声明为对象类型的
var _arr: Array<any> = [];
for (var j: number = 0; j < this.m_tmpArray.length; j++) {
var _armyInfo: model.ArmyInfo = cache.CommonCache.instance.armyList[this.m_tmpArray[j]];
if (_armyInfo["free"] > 0) {
_arr.push({ itemId: _armyInfo["armyId"], num: _armyInfo["free"], type: this.m_bType, headPic: _armyInfo.getHeadIcon(), armyLevel: _armyInfo["armyLevel"], armyType: _armyInfo["armyType"], rally: this.m_rally });
}
}
//其中_armyInfo就是一个对象,它带有armyId, free , getHeadIcon方法,等,通过push方法后,_arr数组中的每个元素就成为带有itemId , num , type ,等属性的对象类型的元素了。