2014-10-30 35 views
0

我試圖運行下面的代碼,我收到以下錯誤:類型錯誤:無法從不確定的讀取屬性「0」 - 使用Javascript

TypeError: Cannot read property "0" from undefined. (line 111) 

有問題的線路是:

perCampaignRows.push([STRATEGISTS[i][1], 

這裏是完整的代碼。

var perCampaignRows = []; 

for (var i = 0; i < STRATEGISTS.length; i++) { 
    var accountIterator = MccApp.accounts() 
     .withCondition("ManagerCustomerId = '" + STRATEGISTS[i][0] + "'") 
     .get(); 

    var mccAccount = AdWordsApp.currentAccount(); 

    while (accountIterator.hasNext()) { 
     var account = accountIterator.next(); 
     MccApp.select(account); 
     Logger.log("Checking " + account.getName() + " - CID: " + account.getCustomerId()); 
     var campaignIterator = AdWordsApp.campaigns() 
      .withCondition("Status = ENABLED") 
      .get(); 

     var activeCampaigns = campaignIterator.totalNumEntities(); 

     if (activeCampaigns === 0) { 
      Logger.log("No Active Campaigns"); 
      perCampaignRows.push([ 
       STRATEGISTS[i][1], 
       STRATEGISTS[i][2], 
       account.getCustomerId(), 
       account.getName(), 
       activeCampaigns, 
       '', 
       '', 
       '', 
       '', 
       '', 
       '', 
       '', 
       '', 
       '', 
       '', 
      ]); 
     } 
     else { 
      Logger.log(activeCampaigns + " Active Campaigns"); 
     } 

     while (campaignIterator.hasNext()) { 
      var campaign = campaignIterator.next(); 
      Logger.log("Campaign: " + campaign.getName()); 
      var mobileBid = checkPlatform(campaign); 
      var isRotatingEvenly = checkAdRotation(campaign); 
      var sitelinkData = checkSitelinks (campaign); 
      var isUsingMobileAds = checkAds(campaign); 
      var callExtData = checkCallExtensions(campaign); 
      var isUsingAdSchedule = checkAdSchedules(campaign); 
      var isSomewhatLimitedByBudget = checkBudgetLimitations(campaign); 

      if (isUsingAdSchedule && isSomewhatLimitedByBudget) { 
       var warnAboutBudgetAndSchedule = "TRUE"; 
      } 
      else { 
       var warnAboutBudgetAndSchedule = "FALSE"; 
      } 

      Logger.log(perCampaignRows); 

      perCampaignRows.push([ 
       STRATEGISTS[i][1], 
       STRATEGISTS[i][2], 
       account.getCustomerId(), 
       account.getName(), 
       activeCampaigns, 
       campaign.getName(), 
       mobileBid, 
       isRotatingEvenly, 
       sitelinkData[0], 
       sitelinkData[1], 
       sitelinkData[2], 
       isUsingMobileAds, 
       callExtData[0], 
       callExtData[1], 
       warnAboutBudgetAndSchedule 
      ]); 
     } 
    } 
} 

我真的不明白爲什麼它不工作,考慮到我在開始時聲明數組。同樣值得注意的是,我確實將STRATEGISTS聲明爲多維數組,如下所示:

var STRATEGISTS = [ 
    ['346-963-8912','Brizza','Arcadio'], 
    ['885-612-1069','Doria','Arcadio'], 
    ['922-596-2785','Edgar','Arcadio'] 
] 

任何想法?

EDIT

根據要求我添加:

Logger.log(STRATEGISTS.length); 
Logger.log(STRATEGISTS); 

第一個記錄51,第二一已記錄的變量如預期。

感謝,

+1

如果你得到那個錯誤,爲了好玩做一個'console.log(STRATEGISTS)',因爲引擎告訴你該對象不存在。 – 2014-10-30 00:18:03

+0

它被取消了上下文......最有可能的是,它在使用之後被聲明或者在另一個作用域中被聲明。 – esp 2014-10-30 00:22:57

+0

完整摘錄:http://pastebin.com/i7T5sdHJ – 2014-10-30 00:25:38

回答

0

所以感謝Guffa我意識到,即使我已經打破了推語句轉換成不同的線路,它被視爲一個。我曾以爲問題出在我的.push實現上,但是這是一個推動變量的問題。

原來我已經錯過了上

var callExtData = checkCallExtensions(campaign); 

等callExtData是空的回報,因此不確定的。

謝謝!

相關問題