Select to view content in your preferred language

How do I get the first array item and then first array item value from my array?

4803
11
Jump to solution
06-22-2015 02:27 PM
ChrisSergent
Deactivated User

Here is a code sample that I have that acquires an array of values:

JS Bin - Collaborative JavaScript Debugging

There are signs that display  the following. I need to get the objectID from the first sign, and then the installed value and then signId and so on. Then I would go to the next item in the array on button click. How would I do that?

OBJECTID: 9263

INSTALLED: null

SIGNID: 1169

FACING: S

VISIBILITY: Good

CONDITION_: Good

SUPPORTID: 691

TEXT:

COLOR1:

DELINEATOR: None

ILLUM: None

OFFSET: null

MOUNTHT: null

BACKING: Aluminum

WIDTH: null

HEIGHT: null

TXTSIZE: null

NUMSIZE: null

COMMENTS:

TWOSIDED: Y

ATTACHTYPE: Bolts

ATTACHNUM: null

ATTACHLOC: Main pole

SITEOBS: Clear

SIGNSHAPE:

COLOR2:

MUTCD: R1-1 (Stop Sign)

GLOBALID: {34E39E75-F785-4272-8F2E-7A13349817F0}

OBJECTID: 9264

INSTALLED: null

SIGNID: 1168

FACING: E

VISIBILITY: Good

CONDITION_: Good

SUPPORTID: 691

TEXT:

COLOR1:

DELINEATOR: None

ILLUM: None

OFFSET: null

MOUNTHT: null

BACKING: Aluminum

WIDTH: null

HEIGHT: null

TXTSIZE: null

NUMSIZE: null

COMMENTS:

TWOSIDED: Y

ATTACHTYPE: Other

ATTACHNUM: null

ATTACHLOC: Main pole

SITEOBS: Clear

SIGNSHAPE:

COLOR2:

MUTCD: D3-1 (Street sign) - Street Name & Parking Signs

GLOBALID: {C8253B28-2EEA-43B2-BFB0-2F1658741E45}

OBJECTID: 9265

INSTALLED: null

SIGNID: 1167

FACING: N

VISIBILITY: Good

CONDITION_: Good

SUPPORTID: 691

TEXT:

COLOR1:

DELINEATOR: None

ILLUM: None

OFFSET: null

MOUNTHT: null

BACKING: Aluminum

WIDTH: null

HEIGHT: null

TXTSIZE: null

NUMSIZE: null

COMMENTS:

TWOSIDED: Y

ATTACHTYPE: Other

ATTACHNUM: null

ATTACHLOC: Main pole

SITEOBS: Clear

SIGNSHAPE:

COLOR2:

MUTCD: D3-1 (Street sign) - Street Name & Parking Signs

GLOBALID: {75AE4A49-7A0E-48B0-A6DD-4FB318BFFC27}

OBJECTID: 22205

INSTALLED: null

SIGNID: 1169

FACING: S

VISIBILITY: Good

CONDITION_: Good

SUPPORTID: 691

TEXT:

COLOR1:

DELINEATOR: None

ILLUM: None

OFFSET: null

MOUNTHT: null

BACKING: Aluminum

WIDTH: null

HEIGHT: null

TXTSIZE: null

NUMSIZE: null

COMMENTS:

TWOSIDED: Y

ATTACHTYPE: Bolts

ATTACHNUM: null

ATTACHLOC: Main pole

SITEOBS: Clear

SIGNSHAPE:

COLOR2:

MUTCD: R1-1 (Stop Sign)

GLOBALID: {D0188C14-D518-42BE-B36E-CCEDB4474BD3}

I have managed to get the first letter of an attribute to increment however:

 on(dom.byId("btnSupportNext"),"click",function(){
            console.log("Next Works");
            var query = new esriQuery();
            var queryTask = new QueryTask(config.signLayerUrl);
            query.returnGeometry = false;
            query.outFields = ["*"];


            


            query.where = "SUPPORTID = " + dom.byId("supportId").value;
            queryTask.execute(query, function (results) {
                // Attempting to know how many signs are in my results
                // Use gettArray.html to get array values
                console.log("Results start now!");
                console.log(results);


                var resultItems = [];
                var resultCount = results.features.length;
                for (var i = 0; i < resultCount; i++) {
                    var featureAttributes = results.features.attributes.ATTACHLOC;
                    for (var attr in featureAttributes) {
                        console.log("Attribute: " + featureAttributes[attr]);
                    }


                }


               
            })


        });
Tags (2)
0 Kudos
11 Replies
thejuskambi
Frequent Contributor

Adding to what Darren has mentioned. If you can hold the query result also a part of Global variable, so that you dont have to make a request to server every time. Query once when you open the dialog/form and clear it when you close the dialog/form.

ChrisSergent
Deactivated User

Good call. I added the variable reset on form opening.

0 Kudos