开发者

Extjs store reader fully qualified json property names

Using Extjs 3+ and server side is sending back the following JSON:

{"com.klistret.cmdb.ci.pojo.QueryResponse": {"com.klistret.cmdb.ci.pojo.successful":true,"com.klistret.cmdb.ci.pojo.count":1,"com.klistret.cmdb.ci.pojo.elements":{"com.klistret.cmdb.ci.pojo.id":123,"com.klistret.cmdb.ci.pojo.name":"Mars","com.klistret.cmdb.ci.pojo.fromTimeStamp":"2010-07-08T16:38:00.478+02:00","com.klistret.cmdb.ci.pojo.createTimeStamp":"2010-07-08T16:38:00.478+02:00","com.klistret.cmdb.ci.pojo.updateTimeStamp":"2010-10-25T15:02:09.446+02:00","com.klistret.cmdb.ci.pojo.type":{"com.klistret.cmdb.ci.pojo.id":1,"com.klistret.cmdb.ci.pojo.name":"{http:\/\/www.klistret.com\/cmdb\/ci\/element\/logical\/collection}Environment","com.klistret.cmdb.ci.pojo.fromTimeStamp":"2009-08-05T11:20:12.471+02:00","com.klistret.cmdb.ci.pojo.createTimeStamp":"2009-08-05T11:20:12.471+02:00","com.klistret.cmdb.ci.pojo.updateTimeStamp":"2009-08-05T11:20:12.471+02:00"},"com.klistret.cmdb.ci.pojo.configuration":{"@www.w3.org.2001.XMLSchema-instance.type":"com.klistret.cmdb.ci.element.logical.collection:Environment","@Watermark":"past","com.klistret.cmdb.ci.commons.Name":"Mars"}}}}

The reader is setup up as follows:


    var reader = new CMDB.JsonReader(
            {
            totalProperty       : 'com.klistret.cmdb.ci.pojo.count',
                successProperty     : 'com.klistret.cmdb.ci.pojo.successful',
                idProperty          : 'com.klistret.cmdb.ci.pojo.id',
                root                : 'com.klistret.cmdb.ci.pojo.elements'
            }, 
            [
            {name: 'Id',   mapping: 'com.klistret.cmdb.ci.pojo.id'},
                {name: 'Name', mapping: 'com.klistret.cmdb.ci.pojo.name'}
            ]
        );

The store as:


    var ds = new Ext.data.Store({
            proxy      : new Ext.data.ScriptTagProxy({
                url    : 'http://sadbmatrix2:55167/CMDB/resteasy/element'
            }),

            reader     : reader 
        });

The reader extends the Ext.data.JsonReader as explained by http://erichauser.net/2007/11/07/more-wcf-json-and-extjs/ to remove the "com.klistret.cmdb.ci.pojo.QueryResponse" start node in the JSON returned from the server.

The extended reader never gets called. Assuming the problem is due to has fully qualified property names in the JSON object returned (ie. "com.klistret.cmdb.ci.pojo.name" r开发者_如何学编程ather than just "name").

Anybody use gotten around this?


We worked it out (well, mostly Matthew did) in the comments:

ScriptTagProxy needs the server to wrap the JSON data in a function call so that your local code can get access to it.

Instead of the server emitting something like:

{here:'is data}

it needs to return

somefunc("{here:'is data'}");

That way, your client-side implementaiton of somefunc() is called and can process the returned data.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜