在服务器端Javascript代码中获取对象预期错误

时间:2022-06-26 15:28:57

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

我收到一个错误,指出在下面的代码中需要一个对象。错误是:

Object Expected: this.regionalRankings[worldRegion][rankType] = this.getRankings(rankType, this.regionalRankingKey[worldRegion]);

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.

函数this.getRankings返回一个对象。

    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 个解决方案

#1


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."

问题是this.regionalRankings [worldRegion] [rankType]要求this.regionalRankings [worldRegion]是一个东西,但是this.regionalRankings是一个空对象,所以“对象是必需的”。

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] = ...
     }
 }    

#1


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."

问题是this.regionalRankings [worldRegion] [rankType]要求this.regionalRankings [worldRegion]是一个东西,但是this.regionalRankings是一个空对象,所以“对象是必需的”。

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] = ...
     }
 }