Not getting anywhere (new guy)

I have been fighting this thing all day. Would someone please look at this code and tell me what I am doing wrong?

It is supposed to load some json with a datasource into a grid. According to the console (the iso one) the resultset has no rows. But the json file has 3 rows.

The code

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>ISO Test</title>
    <SCRIPT>var isomorphicDir="/isomorphic/";</SCRIPT>
    <SCRIPT SRC=/isomorphic/system/modules/ISC_Core.js></SCRIPT>
    <SCRIPT SRC=/isomorphic/system/modules/ISC_Foundation.js></SCRIPT>
    <SCRIPT SRC=/isomorphic/system/modules/ISC_Containers.js></SCRIPT>
    <SCRIPT SRC=/isomorphic/system/modules/ISC_Grids.js></SCRIPT>
    <SCRIPT SRC=/isomorphic/system/modules/ISC_Forms.js></SCRIPT>
    <SCRIPT SRC=/isomorphic/system/modules/ISC_DataBinding.js></SCRIPT>
    <SCRIPT SRC=/isomorphic/skins/SmartClient/load_skin.js></SCRIPT>
    <script>
    isc.DataSource.create({
        ID:"markers",
        dataURL:"/phptest/example.json", 
        dataFormat:"json",
        fields: [
          {type:"text", name: "markers.lat", title: "Lat"},
          {type:"text", name: "markers.lng", title: "Lon"},
          {type:"text", name: "markers.html", title: "Description"}
        ]
    });
    </script>
 </head>

<body>
<div>
<SCRIPT>
isc.Button.create({
title:"Hello",
click:"isc.say('Hello World')"
})
</SCRIPT>
</div>
<div id="gridDiv">
          <script>
            isc.ListGrid.create({
              ID: "markersGrid",
              width:500, height:224, alternateRecordStyles:true, showAllRecords:true,
              dataSource: markers,
              autoFetchData: true
            });
            </script>
</div>
</body></html>

The json file:

{"markers": [
     {"lat":43.65654, "lng":-79.90138, "html":"Some stuff to display in the<br>First Info Window","label":"Marker One"},
     {"lat":43.91892, "lng":-78.89231, "html":"Some stuff to display in the<br>Second Info Window","label":"Marker Two"},
     {"lat":43.82589, "lng":-79.10040, "html":"Some stuff to display in the<br>Third Info Window","label":"Marker Three"}
   ],


 "lines": [
     {"colour":"#FF0000", "width":2, "points":[ {"lat":43.65654 ,"lng":-79.90138 },
                                                {"lat":43.91892 ,"lng":-78.89231 },
                                                {"lat":43.82589 ,"lng":-79.10040 }
                                              ]
     },
     {"colour":"#008800", "width":4, "points":[ {"lat":43.9078 ,"lng":-79.0264 },
                                                {"lat":44.1037 ,"lng":-79.6294 },
                                                {"lat":43.5908 ,"lng":-79.2567 },
                                                {"lat":44.2248 ,"lng":-79.2567 },
                                                {"lat":43.7119 ,"lng":-79.6294 },
                                                {"lat":43.9078 ,"lng":-79.0264 }
                                              ]
     }
   ]

}

It looks like you’re expecting DataSourceField.name to behave like a path, selecting subobject. It doesn’t do that, but DataSourceField.valueXPath will. Name your fields just “lat”, “lng”, “html” and use valueXPaths like “markers.lat” etc.

Tried it…

I tried it. Same result. I included the debug output from the console. The dataset did not change.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>ISO Test</title>
    <SCRIPT>var isomorphicDir="/isomorphic/";</SCRIPT>
    <SCRIPT SRC=/isomorphic/system/modules/ISC_Core.js></SCRIPT>
    <SCRIPT SRC=/isomorphic/system/modules/ISC_Foundation.js></SCRIPT>
    <SCRIPT SRC=/isomorphic/system/modules/ISC_Containers.js></SCRIPT>
    <SCRIPT SRC=/isomorphic/system/modules/ISC_Grids.js></SCRIPT>
    <SCRIPT SRC=/isomorphic/system/modules/ISC_Forms.js></SCRIPT>
    <SCRIPT SRC=/isomorphic/system/modules/ISC_DataBinding.js></SCRIPT>
    <SCRIPT SRC=/isomorphic/skins/SmartClient/load_skin.js></SCRIPT>
    <script>
    isc.DataSource.create({
        ID:"markers",
        dataURL:"/phptest/example.json", 
        dataFormat:"json",
        fields: [
          {type:"text", valueXPath: "markers.lat", name: "lat", title: "Lat"},
          {type:"text", valueXPath: "markers.lng", name: "lng", title: "Lon"},
          {type:"text", valueXPath: "markers.html", name: "html", title: "Description"}
        ]
    });
    </script>
 </head>

<body>
<div>
<SCRIPT>
isc.Button.create({
title:"Hello",
click:"isc.say('Hello World')"
})
</SCRIPT>
</div>
<div id="gridDiv">
          <script>
            isc.ListGrid.create({
              ID: "markersGrid",
              width:500, height:224, alternateRecordStyles:true, showAllRecords:true,
              dataSource: markers,
              autoFetchData: true
            });
            </script>
</div>
</body></html>

Debug:

18:08:16.949:INFO:Log:initialized
18:08:17.586:INFO:ListGrid:markersGrid:Creating new isc.ResultSet for operation 'markers_fetch' with filterValues: {}
18:08:17.586:INFO:ResultSet:isc_ResultSet_2:setCriteria: filter criteria unchanged
18:08:17.590:DEBUG:ResultSet:isc_ResultSet_2:getRange(0,7), cache check: 0,40 firstMissingRow: 0 lastMissingRow: 40
18:08:17.590:DEBUG:ResultSet:isc_ResultSet_2:getRange: guessing forward scrolling
18:08:17.590:INFO:ResultSet:isc_ResultSet_2:getRange(0, 7) will fetch from 0 to 75
18:08:17.590:INFO:ResultSet:isc_ResultSet_2:fetching rows 0,75 from server
18:08:17.619:DEBUG:ResultSet:isc_ResultSet_2:getRange(0, 13) satisfied from cache
18:08:17.654:INFO:Log:isc.Page is loaded
18:08:17.737:XRP5:INFO:ResultSet:isc_ResultSet_2:Received 1 records from server
18:08:17.737:XRP5:DEBUG:ResultSet:isc_ResultSet_2:full length set to: 1
18:08:17.737:XRP5:DEBUG:ResultSet:isc_ResultSet_2:integrating 1 rows into cache at position 0
18:08:17.737:XRP5:INFO:ResultSet:isc_ResultSet_2:cached 1 rows, from 0 to 1 (1 total rows, 1 cached)
18:08:17.737:XRP5:INFO:ResultSet:isc_ResultSet_2:Cache for entire DataSource complete
18:08:17.752:RDQ7:DEBUG:ResultSet:isc_ResultSet_2:getRange(0, 0): returning empty list

]

Sorry XPaths should be “markers**/**lat” et al. Check the docs for valueXPath for what’s legal.

Now getting somewhere :slight_smile:

If you could give me one more tip..

All the values are appearing in one row instead of three. If I solve that I will have something repeatable I can use.

Great job on this code!

I don’t see anything about valueXPath in the refs. Where is that?

Thank you!

Can’t miss it, use search:

http://www.smartclient.com/docs/6.5.1/a/b/c/go.html?search=valueXPath

If you actually want one record per marker, set recordXPath to “/markers” and remove the valueXPath settings. See “Consuming Existing XML and JSON formats” under the client data integration overview to understand how these are applied.

Got it.

Thank you for your help.

I even figured out how to position. I don’t know how I missed the search bit but it is great.