Dojo + DataGrid + JsonRest + json personalizado

I have following problem. My REST web service returns json like this one:

{"response":{"headers":"","items":{"item":[{"@id":"1","email":"admin@admin","firstname":"admin","lastname":"admin","login":"admin"},{"@id":"2","email":"Bennett@Tawney.com","firstname":"Bennett","lastname":"Tawney","login":"bennettabcd"}...

How can I force DataGrid to display items from json above? I can't change REST web service, it must return jsons in this format. Http request is ok and server returns my json, but datagrid is not filled in. ¿Tiene alguna idea?

My "dojo" code is below:

        var store = new Cache(new JsonRest({
            target: settings.vars.API_URL + "/frapi/users/load",
            start: page * rows,
                count: 10,
                sort: [
                    {attribute: "id", descending: true}
                ],
                headers: {
                    "Content-Type": "application/json"
                }
        }), Memory());

        grid = new DataGrid({
            store: new ObjectStore({objectStore: store}),
            queryOptions: {},
            structure:[{
                defaultCell: {
                    width: "auto"
                },
                cells: [
                    {name: "Id", field: "id", width: "50px"},
                    {name: "Login", field: "login"},
                    {name: "Email", field: "email", width: "200px"},
                    {name: "Firstname", field: "firstname"},
                    {name: "Lastname", field: "lastname"}
                ]
            }]            
        }, "grid");

        grid.startup();

Gracias por adelantado

preguntado el 09 de septiembre de 13 a las 21:09

1 Respuestas

OK, I found solution. Please see code below:

    var extractItemsFromResponse = function(deferred) {
        return deferred.then(function(response) {
            return response.response.items.item;
        });
    };

    aspect.after(store, "query", extractItemsFromResponse);

Espero que te ayude.

Respondido el 10 de Septiembre de 13 a las 11:09

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.