2016-08-21 59 views
1

我公司开发的网络GIS工具使用ArcGIS的JavaScript API,并显示使用网格增强道场网格属性的查找任务,找到在地图上的某些功能。一切工作正常,第一次。我可以找到使用关键字和显示属性特征格,但是当我再次使用查找工具,我只能在地图上显示的功能,并首次使用后网格不会刷新。我如何刷新并在网格中显示新值? 的geonet有一个代码示例,像我的代码。我在stackoverflow中搜索并找到了how-to-refresh-datagrid,但我无法使用解决方案。如何刷新数据网格以显示新值?

define([ 
 
    "esri/tasks/FindTask", 
 
    "esri/tasks/FindParameters", 
 
    "esri/symbols/SimpleLineSymbol", 
 
    "esri/symbols/SimpleFillSymbol", 
 
    "esri/Color", 
 

 
    "dgrid/Grid", 
 
    "dgrid/Selection", 
 
    'dojo/_base/declare', 
 
    "dojo/on", 
 
    "dojo/dom", 
 
    "dijit/registry", 
 
    "dojo/_base/array", 
 
    "dijit/form/Button", 
 
    "dojo/parser", 
 
    "esri/symbols/SimpleMarkerSymbol","dojo/data/ItemFileReadStore","dojox/grid/EnhancedGrid","dojo/data/ItemFileWriteStore", 
 
    "dojox/grid/enhanced/plugins/Pagination","dojox/grid/enhanced/plugins/Selector","dojox/grid/enhanced/plugins/Filter","dojox/grid/enhanced/plugins/exporter/CSVWriter","dojo/io/iframe", 
 
    "dojo/domReady!"],function (FindTask, FindParameters, SimpleLineSymbol, SimpleFillSymbol, Color, 
 
           Grid, Selection, declare, on, dom, registry, arrayUtils, Button, parser,SimpleMarkerSymbol,ItemFileReadStore,EnhancedGrid,ItemFileWriteStore) { 
 
     return{ 
 

 
      Find: function (map) { 
 

 
       var findTask, findParams; 
 

 
       var grid, store; 
 

 

 

 

 
       parser.parse(); 
 

 
       registry.byId("searchfind").on("click", doFind); 
 

 
       //Create Find Task using the URL of the map service to search 
 
       findTask = new FindTask("http://...:6080/arcgis/rest/services/layers2/MapServer/"); 
 

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

 
       function doFind() { 
 
        //Set the search text to the value in the box 
 
        var ownerNameBox = dom.byId("findName"); 
 
        findParams.searchText = dom.byId("findName").value; 
 
        findTask.execute(findParams, showResults); 
 
       } 
 
       function showFilterBar(){ 
 
        dijit.byId('grid').showFilterBar(true); 
 
       } 
 

 
       function showResults(results) { 
 

 
        //This function works with an array of FindResult that the task returns 
 
        map.graphics.clear(); 
 
        var symbol = new SimpleMarkerSymbol(); 
 
        symbol.setColor(new Color([0,255,255])); 
 

 
        //create array of attributes 
 
        var items = dojo.map(results, function (result) { 
 
         var graphic = result.feature; 
 
         graphic.setSymbol(symbol); 
 
         map.graphics.add(graphic); 
 
         return result.feature.attributes; 
 
        }); 
 
        var data = { 
 
         identifier: 'OBJECTID', 
 
         label:'OBJECID', 
 
         items: items 
 
        }; 
 

 

 

 
        
 
        store = new dojo.data.ItemFileReadStore({data: data}); 
 

 
        /*set up layout*/ 
 
        var layout = [[ 
 
         {'name': 'OBJECTID', 'field': 'OBJECTID', 'width':'9em',datatype:"number"}, 
 
         {'name': 'Name', 'field': 'Name','width':'16em',datatype:"string",autocomplete:true}, 
 
         {'name':'Address','field':'Address','width':'18em',datatype:"string",autocomplete:true} 
 

 
        ]]; 
 

 
        /*create a new grid:*/ 
 
        var grid = new dojox.grid.EnhancedGrid({ 
 

 
          id: 'grid', 
 
          store:store, 
 
          structure: layout, rowSelector: '1px', 
 
          plugins: { 
 
           // pagination: { 
 
           //  pageSizes: ["5", "10", "All"], 
 
           //  description: true, 
 
           //  sizeSwitch: false, 
 
           //  pageStepper: true, 
 
           //  gotoButton: true, 
 
           //  /*page step to be displayed*/ 
 
           //  maxPageStep: 3, 
 
           //  /*position of the pagination bar*/ 
 
           //  position: "bottom" 
 
           // }, 
 
           filter: { 
 
            // Show the closeFilterbarButton at the filter bar 
 
            closeFilterbarButton: true 
 
            // Set the maximum rule count to 5 
 
            // ruleCount: 5, 
 
            // Set the name of the items 
 
            // itemsName: "songs", 
 

 
           } 
 

 
          } 
 

 
          }, 
 

 
         document.createElement('div')); 
 

 
        /*append the new grid to the div*/ 
 

 
        dojo.byId("grid").appendChild(grid.domNode); 
 

 

 

 
        /*Call startup() to render the grid*/ 
 

 
        grid.startup(); 
 
        grid.setStore(store); 
 
        grid.refresh() 
 

 

 

 

 

 
       } 
 
       //Zoom to the parcel when the user clicks a row 
 

 

 

 

 
        //display the results in the grid 
 

 

 

 
        //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 = event.rows[0].data.BRTID; 
 
        var selectedTaxLot = arrayUtils.filter(map.graphics.graphics, function (graphic) { 
 
         return ((graphic.attributes) && graphic.attributes.BRTID === clickedTaxLotId); 
 
        }); 
 
        if (selectedTaxLot.length) { 
 
         map.setExtent(selectedTaxLot[0].geometry.getExtent(), true); 
 
        } 
 
       } 
 

 
      } 
 

 

 
     } 
 

 

 

 
    } 
 

 

 
)
<body class="claro" role="main"> 
 
<div id="appLayout" style="width:100%; height:100%;" > 
 
     </div> 
 
    <!--<div id="rightpane">--> 
 
    <!--</div>--> 
 
    <div id="center"> 
 
     <!--> 
 
some divs 
 
<!--> 
 
</div> 
 
      <div id="bottom" style="height: 330px" > 
 

 
    </button> 
 

 
     <div id="grid" style="height:98%;font-size: 14px" ></div> 
 
</div> 
 

 
</body>

回答

0

为了改变在网格变化值,你将需要改变网格的存储值。 Dojo网格小部件将根据需要进行更新,因为它直接与您的商店相关。

+0

这里展示如何在Dojo网格控件刷新数据在网络上发现了一个例子:http://jsfiddle.net/v6xbtwfz/ – GibboK

+0

我使用Chrome调试器调试我的代码。商店的价值是正确的。在第一次的代码创建一个使用“VAR电网=新dojox.grid.EnhancedGrid” .AT其他时间的存储中获得新的值格,但是使用“VAR电网=新dojox.grid.EnhancedGrid”不能重建电网。我想我应该一次创建格,但是我不知道如何创建一次电网反复使用 – wetland

+0

@wetland请创建的jsfiddle用微量代码和依赖重现你的问题,我可以尝试修复它为您和给你一个解决方案。请在这里张贴谢谢! – GibboK