0

Dojo 1.8 で JsonRest 機能を取得しようとしています。DataGrid のロードに取り組んでいます。Dojo クライアントが REST サーバーと正常に通信できるようになりました。呼び出しを行います。DataGrid の見出しは入力されていますが、データは入力されていません。REST 呼び出しからの応答は...

{"data":{"fundId":"12345","fundDescription":"ハイリスク株式ファンド","bidPrice":26.8,"offerPrice":27.4,"lastUpdated":"2013-01-23T14:13: 45"}}

私の道場コードは...




        require([
            "dojo/store/JsonRest",
            "dojo/store/Memory",
            "dojo/store/Cache",
            "dojox/grid/DataGrid",
            "dojo/data/ObjectStore",
            "dojo/query",
            "dojo/domReady!" 
        ], function(JsonRest, Memory, Cache, DataGrid, ObjectStore, query) {

            var restStore, memoryStore, myStore, dataStore, grid;

            restStore =  JsonRest({target:"http://localhost:8080/funds/12345"});
            memoryStore = new Memory();
            myStore = Cache(restStore, memoryStore);

            grid = new DataGrid({
                store: dataStore = new ObjectStore({objectStore: myStore}),

        structure: [
            {name:"Fund Id", field:"fundId", width: "200px"},
            {name:"Description", field:"fundDescription", width: "200px"},
            {name:"Bid Price", field:"bidPrice", width: "100px"},
            {name:"Offer Price", field:"offerPrice", width: "100px"},
            {name:"Last Updated", field:"lastUpdated", width: "200px"}
        ]
            }, "target-node-id"); // make sure you have a target HTML element with this id

            grid.startup();

            query("#save").onclick(function(){
                dataStore.save();
            });
        });

    

データをグリッドに正常にロードするには何が欠けていますか?

4

2 に答える 2

0

これは、あなたのREST-Response's datais not an arraybut anが原因である可能性があると思いますobject。実際には次のようになります。

    [{
        "fundId": "12345",
        "fundDescription": "High Risk Equity Fund",
        "bidPrice": 26.8,
        "offerPrice": 27.4,
        "lastUpdated": "2013-01-23T14:13:45"
    }]

ObjectStoreを期待しarrayます。私は通常、あなたのようにはしないので、何を変更しなければならないのかよくわかりません。ただし、JSON-Response が , とにかく与えることを確認する必要がarrayあります。たぶんObjectStore、後でそのようなものにコミットする必要があります:

grid = new DataGrid({
    // getting data, after making sure its an array ;)
    store: dataStore = new ObjectStore({objectStore: myStore.get(0)}),
    ...

何らかの理由でそのようにする必要があるかどうかはわかりませんが、あなたの例では、この例で行われた方法は、私が見る限りあなたのニーズに合うはずです...

于 2013-01-25T06:50:35.590 に答える
0

データが CXF Web サービスから取得され、

{"Customer":[{"id":1,"name":"John-1"},{"id":2," name":"John-2"}]}

ここで答えを見つけました: http://dojotoolkit.org/documentation/tutorials/1.8/populating_datagrid/一方、ストアからデータを手動で取得する必要がありました。

....
restStore.query("", {}).then(function(data){    
    dataStore = new ObjectStore({objectStore: new Memory({ data: data['Customer'] })}),

    grid = new DataGrid({
        store: dataStore,
        items:data.items,
        structure: [
            {name:"Customer ID", field:"id", width: "200px"},
            {name:"Customer Name", field:"name", width: "200px"}
        ]
    }, "target-node-id"); // make sure you have a target HTML element with this id
    grid.startup();
}
...



これが役立つことを願っています。
投稿するのはこれが初めてなので、物事が少しおかしくなったら悪いです。

于 2014-02-27T20:33:50.300 に答える