Note that there are some explanatory texts on larger screens.

plurals
  1. POExt.data.JsonStore getCount() returns 0 records web service
    primarykey
    data
    text
    <p>I am working on a Sencha Touch application, and can't get data from my web service.</p> <p>The following code worked for another user on <a href="http://www.sencha.com/forum/showthread.php?74361-Solved-JsonStore-and-asp.net-web-service/page4" rel="nofollow" title="Sencha's forums">sencha's forums</a>,page 4. I've modified it to match my web services output json.</p> <pre><code>var myStore = new Ext.data.JsonStore({ id: 'Agents', proxy: new Ext.data.HttpProxy({ url: 'ws/Service.asmx/GetAgents' ,method: 'post' ,jsonData: {} ,headers: { 'Content-Type': 'application/json; charset=utf-8;'} ,reader:{root:'d', record:'rows'} }), totalProperty: 'd.totalRows', idProperty: 'AgentID', fields: ['AgentID', 'FirstName','LastName'], autoLoad:'true', listeners: { beforeload: function(myStore, options) { console.log('beforeload: myStore.count = ' + myStore.getCount()); console.log(options); }, load: function(myStore, records, options) { console.log('load: ' + myStore.getCount()); console.log(records) console.log(options); }, exception: function(misc) { console.log('exception:'); console.log(misc); } } }); </code></pre> <p>Firebug Console Output:</p> <pre><code>beforeload: myStore.count = 0 load: 0 [] true </code></pre> <p>Firebug confirms the JSON returned from 'ws/Service.asmx/GetAgents' is:</p> <pre><code>{"d":{"success":true,"totalRows":2,"rows":[{"AgentID":1,"FirstName":"Jelena","LastName":"Akerhus"},{"AgentID":2,"FirstName":"Londo","LastName":"Molari"}]}} </code></pre> <p>However, when I type 'myStore.getCount()' into the console I get 0 records.</p> <p>Here is the part of the code for Service.asmx:</p> <pre><code>[System.Web.Script.Services.ScriptService] public class Service : System.Web.Services.WebService { [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true, XmlSerializeString = false)] public object GetAgents() { List&lt;Agent&gt; agents = new List&lt;Agent&gt;(); agents.Add( new Agent(1, "Jelena", "Akerhus") ); agents.Add( new Agent(2, "Londo", "Molari") ); object data = new { success = true, totalRows = agents.Count, rows = agents }; return data; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload