6 Replies - 590 Views - Last Post: 02 July 2013 - 09:25 AM

#1 troyb408  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 69
  • Joined: 18-August 12

Javascripting loop question

Posted 01 July 2013 - 02:14 PM

I will do my best to explain with out posting a ton of code. I have a esri map that I've created. On this map there are several attributes one in particular is the STATE name. Now using dojo i've added my base map then created a feature layer and added my STATE map. I have a csv file that contains all the states and some other data. In javascript I'm trying to connect the state map to the csv file. I'm getting stuck and really dont know how to go about this issue. I just trying to loop through the attributes on the map and those that equal the names from the csv file assign it that row of data.

I'm trying to say for each STATE name in raw assign it that raw row.
Hope I didnt confuse anybody because think I confused myself again and just need a break from it.


data = the data from the csv file
STATE = the attributes on the map

Here is my code:
        function drawFeatureLayer(data) 
        {
            console.log("Loaded: " + data.length);
            console.log(data);            
            var raw = data;
            var valMin = Infinity;
            var valMax = -Infinity;

            for("STATE" in raw) 
            {
                
            }
         }



Thanks any help tips pointers trick anything would be greatly appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Javascripting loop question

#2 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3480
  • View blog
  • Posts: 11,833
  • Joined: 12-December 12

Re: Javascripting loop question

Posted 01 July 2013 - 02:32 PM

I don't think you are supplying enough information to obtain meaningful help.

Are there errors in your browser's Console? What are they and what line(s) do they refer to?

If not what is going wrong with your code?

Added: But your for..in is incorrect, unless there is a version of this of which I am unaware(?).

for (var prop in obj) {

is used to loop through the enumerable properties of an object.

This post has been edited by andrewsw: 01 July 2013 - 02:35 PM

Was This Post Helpful? 1
  • +
  • -

#3 laytonsdad  Icon User is offline

  • Cheese and Sprinkles
  • member icon

Reputation: 440
  • View blog
  • Posts: 1,867
  • Joined: 30-April 10

Re: Javascripting loop question

Posted 01 July 2013 - 02:33 PM

I am a bit confused to what the actual question is. Are you asking how to loop through the data and add it to the row that it corresponds to?

What type is data returned as, is it an object? Can you post your console data from the console.log(data); so we can see the returned data?
Was This Post Helpful? 0
  • +
  • -

#4 troyb408  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 69
  • Joined: 18-August 12

Re: Javascripting loop question

Posted 01 July 2013 - 04:01 PM

Yes my syntax i see now is incorrect. I have attributes such as STATE on the map and in my csv file i have a column name STATE. I need to loop through my attributes (data) (I assigned raw to equal DATA) and each state name that equals the csv column state name I need that row assigned.

View Postlaytonsdad, on 01 July 2013 - 02:33 PM, said:

I am a bit confused to what the actual question is. Are you asking how to loop through the data and add it to the row that it corresponds to?

What type is data returned as, is it an object? Can you post your console data from the console.log(data); so we can see the returned data?



The console log of data is 2015 items such as

here is an example

StateColumn | Another column
Ohio |1234
Was This Post Helpful? 0
  • +
  • -

#5 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,236
  • Joined: 08-June 10

Re: Javascripting loop question

Posted 01 July 2013 - 10:41 PM

so essentially, data is a string, hence you have to treat it like one or convert it to an iterable structure (String.split() comes to mind).
Was This Post Helpful? 0
  • +
  • -

#6 troyb408  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 69
  • Joined: 18-August 12

Re: Javascripting loop question

Posted 02 July 2013 - 08:45 AM

after looking at it this is what i've come up with

            console.log("Loaded: " + data.length);
            console.log(data);
                       

            var raw = data.split("\n");            
            console.log(data[1]);
                     
            var valMin = Infinity;
            var valMax = -Infinity;
            var arrayForBreaks = [];

            for (var i = 1; raw.length; i++) 
            {
                var row = raw[i].split("/\r?\n/g");
                var csvData = raw[1];
                var col1 = null;
                if (csvData == raw[1]) 
                {
                    col1 = csvData;
                } //end if

            } //end for loop  



Now the problem is that the split method isnt working and i'm getting individual characters. The log of data[1] is "t"
Was This Post Helpful? 0
  • +
  • -

#7 troyb408  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 69
  • Joined: 18-August 12

Re: Javascripting loop question

Posted 02 July 2013 - 09:25 AM

Never mind I took a break and before looking at this again and saw I was logging the row variable. Thanks to those that helped
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1