开发者

ExtJS JSON and Grails

I have problems getting data from grails using extjs. My Grails controller code is:

   def getElements = { 
        def json =   [
         "firstName": "John",
         "lastName": "Smith",
         "age": 25,
         "address": [
开发者_Go百科             "streetAddress": "21 2nd Street",
             "city": "New York",
             "state": "NY",
             "postalCode": "10021"
         ],
         "phoneNumbers": [
             [ "type": "home", "number": "212 555-1234" ],
             [ "type": "fax", "number": "646 555-4567" ]
         ],
         "newSubscription": false,
         "companyName": null
        ] as JSON

        response.setHeader('Content-disposition', 'filename="json"')
        response.contentType = "text/json";
        render (json) as JSON
        }

When I browse to .../controller/getElements I do get an JSON Element as download.

Actually, I want to use this json in ExtJS. My ExtJS code:

...
var jsonstore = new Ext.data.JsonStore({
   url: "datenabruf/getElements",
   fields: [ 'firstName','lastName'],
   paramNames: { start : "offset", limit :"max", sort : "sort", dir : "order" }
});
alert(jsonstore.getTotalCount());

The problem is, that I get 0 elements. Am I missing some parameters?


Solved!

i just had to load the store afterwards.

jsonstore.load({callback: function(r) { alert("juhu"); }})
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜