开发者

In ExtJS, how to define jsonreader for different json input formats?

I have an external source that generates JSON in given format. I need to use ScriptTagProxy to access that data. Format of data is (two records):

{
"COLUMNS":["KEDBID","EMPID","KE","SOLUTION","ATTACH_KE","ATTACH_SOLUTION"],
"DATA":[
[1,36661,"While adding a new user, if his\/her profile is missing, it could be LDAP    server issue.","Contact Mr. ABC from infra team to get user's profile corrected on server","screenshots.jpg","conacts.doc"],
[2,36661,"The error code # 123445 is trivial that may occur at particular time.","To resolve this issue, we will need to ask DBA team to refresh database. That will fix this type of errors","NA","NA"]
]
} 

How to define jsonreader for this data? As i have seen that root should be like:

{ROOT: [ {field1:data1,field2:data1},{field1:data2,field2:data2}]}

while my JSON is like:

{fieldnames:['field1','field2'],
 ROOT:[ [data1ForField1,data1ForField2],[data2ForField1,data2ForField2] ]
}

UPDATE

Adding one more case: Similarly can we have a jsonreader for;

    {"ROWCOUNT":8,
"COLUMNS":["CATID","CATEGORY"],
"DATA":{"CATID":[1,2,3,4,5,6,7,8],"CATEGORY":["Optimization","Automation","Process Improvement","Tool","Other","Another One","ThisHas'","More^!@#(){}"]}} 

where 1-->Optimization, 2-->Automation, 3-->Process Improvement etc.

Basically I need to return data from ColdFusion query object by serializing query object. Serialization in CF Query can return data in above two formats.

I'm still new to Ext World!! Hope to get some support.

Best Regards, Tushar Saxena


Below is the code where I'm facing issue. The data is being coming up in store as it is available to ComBox.. but not able to read data using each function or by other means? So is it that Data in store can only be fed to components? In another example I created a simplestore (ArrayStore) paased data manually using loadDATA().. there each function was working!!!

In below case to if I add one record after load using ADD(), each function would get executed one time showing data that I just added... and that just added data is not available to components!!! How come!!!

May be I'm missing some very basic concept as I'm still very new to EXT.

Would be really greatful for response.

var proxy = new Ext.data.ScriptTagProxy({
            url: 'http://127.0.0.1:8500/extex/kebyid.cfm',
            method: 'POST'
        });

        var rec = Ext.data.Record.create([
            {name: 'EMPID', mapping: 1},
                     {name: 'KE', mapping: 2},
                     {name: 'SOLUTION', mapping: 3},
                     {name: 'ATTACH_KE', mapping: 4},
                     {name: 'ATTACH_SOLUTION', mapping: 5}
        ]);

        var myReader = new Ext.data.ArrayReader({
                    idIndex: 0,
                    root: 'DATA'
                }, rec);



        var store = new Ext.data.ArrayStore({
                 proxy: new Ext.data.HttpProxy({
                        url: '/extex/kebyid.c开发者_Python百科fm',
                            method: 'POST'
                }),

                autoSave: true,
                autoLoad: true,
                root: 'DATA',
                fields: [
                     {name: 'KEID', mapping: 0},
                     {name: 'EMPID', mapping: 1},
                     {name: 'KE', mapping: 2},
                     {name: 'SOLUTION', mapping: 3},
                     {name: 'ATTACH_KE', mapping: 4},
                     {name: 'ATTACH_SOLUTION', mapping: 5}
                ]
            });


    store.each(function(){
        alert('!!!!'); //**************NOT WORKING
    });
    var catCB = new Ext.form.ComboBox({
            fieldLabel: 'Category',
            layout:'absolute',
            x: 100,
             y: 5,
            store: store, //************* DATA IS THERE AS STORE IS PROVIDING DATA TO COMBOBOX
            emptyText:'Select Category...',
            valueField : 'KEID',
            displayField : 'KE',
            hiddenName : 'category',
            hiddenvalue : 'None', 
            mode: 'local',
            editable : false,
            lastQuery: '',
            renderTo: Ext.get("d1"),
            listeners: {

                'beforequery': function(qe){
                      qe.forceAll = true;
                }}
        });


First of all, you cannot use your server's output for scriptTagProxy. scriptTagProxy utilises JSONP technology. So output should look like this:

callback({
  "COLUMNS":["KEDBID","EMPID","KE","SOLUTION","ATTACH_KE","ATTACH_SOLUTION"],
  "DATA":[
    [1,36661,"While adding a new user, if his\/her profile is missing, it could be LDAP    server issue.","Contact Mr. ABC from infra team to get user's profile corrected on server","screenshots.jpg","conacts.doc"],
    [2,36661,"The error code # 123445 is trivial that may occur at particular time.","To resolve this issue, we will need to ask DBA team to refresh database. That will fix this type of errors","NA","NA"]
  ]
});

Then simply use ArrayStore as your store. It uses ArrayReader by default:

var store = new Ext.data.ArrayStore({
    proxy: new Ext.data.ScriptTagProxy({
        url: 'http://example.com/get_data.php'
    }),
    root: 'DATA',
    fields: [
       'id',
       // ...,
       // ...,
       // ...
    ]
});

UPDATE
I forgot that you are using 'DATA' as root property. Added it to store config.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜