How to loop through individual graphics and show only a selected group

824
3
09-13-2012 02:49 PM
PhoebeMcNeally
New Contributor
My goal is to loop through the results of a query task and return only the graphics that match the returned query records.

I have created a query task that queries a table and returns the matching set of results. I then created a graphics layers with attributes from a points feature class. So I now have to arrays that I need to loop through and only show the points that are in both. I am using graphics since variations of this query will be repeated many times.  My show results function is working except it only returns the first matched individual graphic and not the whole set. Just started developing again and am probably missing something very basic.

My code is:

// Function to show the shots that were returned in the table query (attached to graphics)
      function showResults(results) {
     
       dojo.forEach(results.features, function (resultsFeature) {
    dojo.forEach(shotLayer.graphics, function (shotLayerGraphic) {
    
     if (resultsFeature.attributes.LOC == shotLayerGraphic.attributes.Path) {
      shot.show();
           alert("test"+ resultsFeature.attributes.LOC "and" + shotLayerGraphic.attributes.Path);
     }
    });

        
    });
  }

The alert lets me know that it is cycling through correctly, but shot.show(); only displays one point.

My graphics layer is shotLayer and the individual graphics is the shot variable (both declared globally)

Any help would be greatly appreciated
0 Kudos
3 Replies
StephenLead
Regular Contributor III
My graphics layer is shotLayer and the individual graphics is the shot variable (both declared globally)


When you post a code sample, it helps if you can use the Code tags (the # at the top right of the editor) so the formatting isn't stripped out.

/ Function to show the shots that were returned in the table query (attached to graphics)
function showResults(results) {

     dojo.forEach(results.features, function (resultsFeature) {
             dojo.forEach(shotLayer.graphics, function (shotLayerGraphic) {
                 
                    if (resultsFeature.attributes.LOC == shotLayerGraphic.attributes.Path) {
                        shot.show();
                 alert("test"+ resultsFeature.attributes.LOC "and" + shotLayerGraphic.attributes.Path);
                    } 
                });
             });
        }


It looks as if you're not re-setting "shot", so the same feature is being displayed at each iteration of the loop.

Cheers,
Steve
0 Kudos
PhoebeMcNeally
New Contributor
Thanks Steve for the code suggestion, I'll make sure to post it that way next time.

Given my newness, I don't know how to reset the Shot.show();

When using the dojo.forEach can you loop through it using shot.show like you would with a for loop?

Thanks for your help
0 Kudos
StephenLead
Regular Contributor III
Can you include the full code (perhaps as a zipped attachment), or point us to the live site somewhere?
0 Kudos