在ExtJS中,如何针对不同的json输入格式定义jsonreader?

发布于 2024-11-27 07:12:51 字数 3766 浏览 0 评论 0原文

我有一个外部源,可以生成给定格式的 JSON。我需要使用 ScriptTagProxy 来访问该数据。数据格式为(两条记录):

{
"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"]
]
} 

如何为该数据定义jsonreader?正如我所看到的,根应该是这样的:

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

而我的 JSON 是这样的:

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

更新

添加一种情况: 同样,我们可以有一个 jsonreader;

    {"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^!@#(){}"]}} 

其中1-->优化,2-->自动化,3-->流程改进等。

基本上我需要通过序列化查询对象从ColdFusion查询对象返回数据。 CF Query 中的序列化可以返回以上两种格式的数据。

我对 Ext World 还是个新手!!希望能得到一些支持。

此致, Tushar Saxena


下面是我遇到问题的代码。数据正在存储中,因为 ComBox 可以使用它..但无法使用每个功能或通过其他方式读取数据?那么存储中的数据只能输入到组件吗?在另一个例子中,我使用 loadDATA() 手动创建了一个 simplestore (ArrayStore) paased 数据。每个函数都在工作!

在下面的情况下,如果我在加载后使用 ADD() 添加一条记录,每个函数都会执行一次,显示我刚刚添加的数据......并且刚刚添加的数据对组件不可用!怎么会!!!

可能我缺少一些非常基本的概念,因为我对 EXT 还很陌生。

如果能得到回复,我将不胜感激。

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.cfm',
                            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;
                }}
        });

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.cfm',
                            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;
                }}
        });

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

御守 2024-12-04 07:12:51

首先,您不能将服务器的输出用于 scriptTagProxy。 scriptTagProxy 利用 JSONP 技术。因此输出应如下所示:

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"]
  ]
});

然后只需使用 ArrayStore 作为您的商店。默认情况下它使用 ArrayReader:

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

更新
我忘记您正在使用 'DATA' 作为根属性。添加它来存储配置。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文