正如你在代码中看到的那样,我试图在一个对象中动态创建数组,它在调试时没有问题,但是当我尝试在数组中使用push方法时,它会抛出一个错误。顺便说一句,这是谷歌应用程序脚本。
在对象[object Object]中找不到推送功能:TypeError。 (第32行,档案
var LoopQuestGuildAchievementReward = function (spread_sheet, master_name, is_update) {
initializeBase(this, MasterBase, [spread_sheet, master_name, is_update]);
this.guild_achievement_columns = new Object();
this.create_guild_achievement_columns = function () {
var guild_achievement_coloumn_names = ['ids', 'event_ids', 'range_starts', 'range_ends', 'incentive_ids'];
for (var i = 0; i < guild_achievement_coloumn_names.length; i++) {
if (!this.guild_achievement_columns[guild_achievement_coloumn_names[i]]) {
this.guild_achievement_columns[guild_achievement_coloumn_names[i]] = {};
};
};
};
};
LoopQuestGuildAchievementReward.prototype.setMaster = function(option) {
if (!option || !option.summary_values || !option.batch_reward_values) {
throw "Argument exception.";
};
var event_id = option.summary_values[8][0];
var incentive_values = option.batch_reward_values;
var incentive_master_id = Commons.getIncentiveId(1, event_id, 5);
var data_row_number = searchRowNumberWrittenLavelInColumn_(incentive_values, 1, "reach num") + 1;
var guild_achievement_last_id = Commons.getLatestId("loop_quest_guild_achievement_reward", "ja") + 1;
this.create_guild_achievement_columns();
while (data_row_number < incentive_values.length && incentive_values[data_row_number][1] != "") {
var reach_number = incentive_values[data_row_number][1];
Logger.log(this.guild_achievement_columns.ids);
this.guild_achievement_columns.ids.push(guild_achievement_last_id); // <- this where the error message points (line no. 32)
// this.guild_achievement_columns.event_ids.push(event_id);
// this.guild_achievement_columns.range_starts.push(reach_number);
// this.guild_achievement_columns.range_ends.push(reach_number - 1);
// this.guild_achievement_columns.incentive_ids.push(incentive_master_id);
guild_achievement_last_id++;
incentive_master_id++;
data_row_number++;
}
Logger.log(this.guild_achievement_columns);
};
答案 0 :(得分:0)
在询问我的上级后,他提到花括号引用对象和括号引用数组。
对象:this.guild_achievement_columns [guild_achievement_coloumn_names [i]] = {};
数组:this.guild_achievement_columns [guild_achievement_coloumn_names [i]] = [];