1

私はext Jsが初めてです。

ajax 呼び出しがあります。アラートで応答テキストを確認できましたが、responseText をデコードすると想定される次の行は、アラート ボックスに結果を生成しません。

私の機能は次のようになります:

function openToRecipients()
{

    Ext.Ajax.request({
        url: "Redirector?id=ClinicalInitiateForm&wfid=CLINICALONGOINGWFINITIATE",
        method: 'POST',                 
            success: function(response, opts) 
            {
                alert(response.responseText);
                var dataCurrent = Ext.util.JSON.decode(response.responseText);
                alert(dataCurrent );
                var jsonStr = dataCurrent.cData;
                recipientJsonResponse = dataCurrent.dataGrid;
                var myObject = eval('(' + jsonStr + ')');
                gridStore = new Ext.data.JsonStore({
                    id : 'gridStore',
                    autoLoad : true,
                    data : myObject,
                    root : 'data',
                    fields:['NAME',
                               'CLIENT',
                               'DESCRIPTION'
                         ],
                    listeners :{
                        load  : gridDisplay
                    }
                });
                },
            failure: function(response, opts) {
                alert("fail");
            }

    });

}

これは文字列に変換した後の私のjsonです

"formFields" : [ {
    "id" : "NAME",
    "set" : "",
    "label" : "Name",
    "dataType" : "string",
    "editType" : "static",
    "clientConfig" : "",
    "hide" : "False",
    "required" : "",
    "mask" : "",
    "maxValue" : "",
    "maxLength" : "",
    "minValue" : "",
    "value" : "",
    "showIf" : "",
    "options" : "",
    "prePopulate" : "",
    "shortForm" : "",
    "comments" : "",
    "optionsValue" : "",
    "currentValue" : "",
    "disabled" : "",
    "qTip" : "",
    "hover" : ""
  }, {
    "id" : "CLIENT",
    "set" : "",
    "label" : "Client",
    "dataType" : "string",
    "editType" : "static",
    "clientConfig" : "",
    "hide" : "False",
    "required" : "",
    "mask" : "",
    "maxValue" : "",
    "maxLength" : "",
    "minValue" : "",
    "value" : "",
    "showIf" : "",
    "options" : "",
    "prePopulate" : "",
    "shortForm" : "",
    "comments" : "",
    "optionsValue" : "",
    "currentValue" : "",
    "disabled" : "",
    "qTip" : "",
    "hover" : ""
  }, {
    "id" : "DESCRIPTION",
    "set" : "",
    "label" : "Description",
    "dataType" : "string",
    "editType" : "static",
    "clientConfig" : "",
    "hide" : "False",
    "required" : "",
    "mask" : "",
    "maxValue" : "",
    "maxLength" : "",
    "minValue" : "",
    "value" : "",
    "showIf" : "",
    "options" : "",
    "prePopulate" : "",
    "shortForm" : "",
    "comments" : "",
    "optionsValue" : "",
    "currentValue" : "",
    "disabled" : "",
    "qTip" : "",
    "hover" : ""
  } ],

そして、これは私のデータです

{'data':[{"NAME":"Shan","CLIENT":"CSC","DESCRIPTION":"Computer science"}]}

このデータをグリッドに含めるにはどうすればよいですか

4

1 に答える 1

1

使用できるコードは次のとおりです。

var myStore = Ext.create( "Ext.data.JsonStore", {
    fields: [ "firstname", "lastname" ], // the fields of each item (table line)
    proxy: {
        type: "ajax",    // the proxy uses ajax
        actionMethods: { // this config is not necessary for you. I needed to use it to be able to work with the echo service of jsFiddle. if you want to use post (as I saw in your post, you can skip this)
            create: "POST",
            read: "POST",
            update: "POST",
            destroy: "POST"
        },
        url: "/echo/json/", // here will come your URL that returns your JSON (in your case "Redirector?id..."
        reader: {
            type: "json",  // this store reads data in json format
            root: "items"  // the itens to be read are inserted in a "items" array, in you case "formFields"
        }
    }
});

// in jsFiddle, we need to send the JSON that we want to read. In your case, you will just call .load() or set the autoLoad config of the store to true. If you want send adition parameters, you can use the sintax below.
myStore.load({
    params: {
        // everything inside the encode method will be encoded in json (this format that you must send to the store)
        json: Ext.encode({
            items: [{
                "firstname": "foo",
                "lastname": "bar"
            }, {
                "firstname": "david",
                "lastname": "buzatto"
            }, {
                "firstname": "douglas",
                "lastname": "adams"
            }]
        })
    }
});

// creatin the grid, setting its columns and the store
Ext.create( "Ext.grid.Panel", {
    title: "My Grid",
    columns: [{
        header: "First Name",
        dataIndex: "firstname"   // the dataIndex config is used to bind the column with the json data of each item
    }, {
        header: "Last Name",
        dataIndex: "lastname"
    }],
    store: myStore,           // the store created above
    renderTo: Ext.getBody()   // render the grid to the body
});

ここでフィドルにアクセスできます: http://jsfiddle.net/cYwhK/1/ ドキュメント:

言い忘れていたもう 1 つの考えは、ストアでフィールドの配列の代わりにモデルを使用できるということです。モデルはオブジェクト指向言語のクラスのようなものです。見てみましょう: http://dev.sencha.com/deploy/ext-4.1.0-gpl/docs/index.html#!/api/Ext.data.Model

于 2012-07-19T07:05:30.207 に答える