dexconor

parser.parse();  is not a function

Discussion created by dexconor on May 9, 2014
Latest reply on Jul 16, 2014 by ykchin
Hi, I was integrating https://developers.arcgis.com/javascript/jssamples/find_map_datagrid.html
example into my map.

but I got:

TypeError: parser.parse is not a function
parser.parse();

here is my code below
var layerConfig = {
    urlTiled: "http://localhost:6080/arcgis/rest/services/v1/BaseMap42114/MapServer",
    urlInfo: "http://localhost:6080/arcgis/rest/services/aggiemap_beta/beta_MapInfo/MapServer",
    urlV1Info: "http://localhost:6080/arcgis/rest/services/v1/MapInfo/MapServer",
    qBldg: "http://localhost:6080/arcgis/rest/services/v1/MapInfo/MapServer/6"
};
var map;

require(["esri/map", "esri/layers/ArcGISTiledMapServiceLayer", "esri/layers/ArcGISDynamicMapServiceLayer", "esri/dijit/HomeButton", "esri/tasks/FindTask",
    "esri/tasks/FindParameters", "esri/symbols/SimpleMarkerSymbol", "esri/symbols/SimpleLineSymbol", "esri/symbols/SimpleFillSymbol", "dijit/layout/BorderContainer", "dijit/layout/ContentPane",
    "esri/Color", "dojo/on", "dojo/dom", "dijit/registry", "dojo/_base/array", "dojo/_base/connect", "dojox/grid/DataGrid", "dojo/data/ItemFileReadStore", "dijit/form/Button", "dojo/parser", "dojo/domReady!"],

function (Map, Tiled, ArcGISDynamicMapServiceLayer, HomeButton, FindTask, FindParameters, SimpleMarkerSymbol, SimpleLineSymbol, SimpleFillSymbol, Color, on, dom, registry, arrayUtils, connect, DataGrid, ItemFileReadStore, parser, Button) {
    var findTask, findParams;
    var map, center, zoom;
    var grid, store;
    parser.parse();
    registry.byId("search").on("click", doFind);

    var map = new Map("map", {
        center: [-96.345680, 30.612473],
        zoom: 16,
        basemap: "topo"
    });
    var home = new HomeButton({
        map: map
    }, "HomeButton");
    home.startup();
    var tiled = new Tiled(layerConfig.urlTiled);
    var tamuInfo = new ArcGISDynamicMapServiceLayer(layerConfig.urlV1Info);
    map.addLayers([tiled, tamuInfo]);

    //search fnc
    //Create Find Task using the URL of the map service to search
    findTask = new FindTask(layerConfig.urlV1Info);

    map.on("load", function () {
        //Create the find parameters
        findParams = new FindParameters();
        findParams.returnGeometry = true;
        findParams.layerIds = [0];
        findParams.searchFields = ["MapDisplay"];
        findParams.outSpatialReference = map.spatialReference;
        console.log("find sr: ", findParams.outSpatialReference);
    });

    function doFind() {
        //Set the search text to the value in the box
        findParams.searchText = dom.byId("searchField").value;
        findTask.execute(findParams, showResults);
    }

    function showResults(results) {
        //This function works with an array of FindResult that the task returns
        map.graphics.clear();
        var symbol = new SimpleFillSymbol(
        SimpleFillSymbol.STYLE_SOLID,
        new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([98, 194, 204]), 2),
        new Color([98, 194, 204, 0.5]));

        //create array of attributes
        var items = arrayUtils.map(results, function (result) {
            var graphic = result.feature;
            graphic.setSymbol(symbol);
            map.graphics.add(graphic);
            return result.feature.attributes;
        });

        //Create data object to be used in store
        var data = {
            identifier: "PARCELID", //This field needs to have unique values
            label: "PARCELID", //Name field for display. Not pertinent to a grid but may be used elsewhere.
            items: items
        };

        //Create data store and bind to grid.
        store = new ItemFileReadStore({
            data: data
        });
        var grid = registry.byId("grid");
        grid.setStore(store);
        grid.on("rowclick", onRowClickHandler);

        //Zoom back to the initial map extent
        map.centerAndZoom(center, zoom);
    }

    //Zoom to the parcel when the user clicks a row
    function onRowClickHandler(evt) {
        var clickedTaxLotId = evt.grid.getItem(evt.rowIndex).PARCELID;
        var selectedTaxLot = arrayUtils.filter(map.graphics.graphics, function (graphic) {
            return ((graphic.attributes) && graphic.attributes.PARCELID === clickedTaxLotId);
        });
        if (selectedTaxLot.length) {
            map.setExtent(selectedTaxLot[0].geometry.getExtent(), true);
        }
    }
    //end search

}); //end

I'm not sure that what makes this error.
the map before I add this search function was totally fine.

Thank you for your time!

Outcomes