views:

206

answers:

1

I am getting an error stating that an object is expected in the below code.

Declarations...

this.regions = {};
this.regions = ["US", "Europe", "Asia"];    
this.regionalRankingKey = ["SP500", "GBE", "CNG"]; //this is the ranking model key for pulling up the rankings object.
this.rankingTypes = ["gainers", "losers", "actives"];
this.regionalRankings = {};
this.rankingWSODIssues = [];

marketSummary_data.prototype.initRankingsNew = function(){

for(var worldRegion in this.regions){        

    for (var rankType in this.rankingTypes){

        //this is the line getting the error.
        this.regionalRankings[worldRegion][rankType] = this.getRankings(rankType, this.regionalRankingKey[worldRegion]);

        for(var i = 0; i < 5; i++){

            this.rankingWSODIssues.push(this.regionalRankings[worldRegion][rankType].value("Result[0].Row[" + i + "].WSODIssue"));

        }
    }    
}

for(var item in this.rankingWSODIssues){

    Response.Write("<p>" + item + ": " + rankingWSODIssues[item] + "</p>");

}

}

the function this.getRankings returns an object.

marketSummary_data.prototype.getRankings = function(rankingType, rankingSet){
//ranking types Epctchg+ (pct gainers) 
//Epctchg- (pct losers) 
//Edollar+ (net gainers) 
//Edollar- (net losers) 
//Evol+ (highest volume) 

//rankingSets    

if (rankingType == "gainers"){
    rankingType = "Epctchg+";
}
if (rankingType == "losers"){
    rankingType = "Epctchg-";
}
if (rankingType == "actives"){
    rankingType = "Evol+";
}

var rankings = User.CreateObject("WIT.Rankings.1")

   rankings.SetVariableName("Rankings")
   rankings.SetInput("Ranking.RT", 0)
   rankings.SetInput("Ranking.Type", rankingType)
   rankings.SetInput("Ranking.Set", rankingSet)
   rankings.SetInput("Ranking.Rows", 5)
   rankings.SetInput("Ranking.Symbolset", "BridgeStreet");
   rankings.SetInput("Ranking.MinPrice", 0);  // only want stocks trading higher> 0
   rankings.Retrieve();

return rankings; }

Any ideas on what I am doing wrong here?

+1  A: 

The problem is that this.regionalRankings[worldRegion][rankType] requires that this.regionalRankings[worldRegion] be something, however this.regionalRankings is an empty object, so an "Object is Required."

I think what you intended to do is:

for(var worldRegion in this.regions){        
    this.regionalRankings[worldRegion] = {}; // Make it into an object.
    for (var rankType in this.rankingTypes){
        this.regionalRankings[worldRegion][rankType] = ...
     }
 }
grammar31
This is correct. I was looking into the same issue and you beat me by a few minutes. +1
Jose Basilio
This is indeed correct. I now know to check for this every time. Thanks!
Shane Larson