1

我有一个以给定格式生成 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 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^!@#(){}"]}} 

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

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

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

最好的问候, Tushar Saxena


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

在以下情况下,如果我在使用 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;
                }}
        });
4

1 回答 1

1

首先,您不能将服务器的输出用于 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'的是根属性。将其添加到存储配置。

于 2011-08-02T15:04:13.117 回答