Как привязать JSON к сетке EXTJS - PullRequest
2 голосов
/ 05 мая 2011

Может кто-нибудь объяснить мне, почему это не работает?Никаких ошибок.

Ext.onReady(function () {
    //Ext.Msg.alert('Status', 'Changes saved successfully.');
    Ext.define('Bond', {
        extend: 'Ext.data.Model',
        fields: ['CUSIP', 'DESCRIPTION', 'COUPONRATE', 'ASKPRICE']
    });

    var store = new Ext.data.Store({
        model: 'Bond',
        proxy: {
            type: 'ajax',
            url: 'http://localhost:3197/Home/GetSecondaryOfferings',
            reader: {
                type: 'json',
                root: 'items',
                totalProperty: 'totalCount'
            }
        }
    });
    store.load();

    var grid = new Ext.grid.GridPanel({
        store: store,
        columns: [
            { header: 'CUSIP', dataIndex: 'CUSIP' },
            { header: 'Description', dataIndex: 'DESCRIPTION', width: 100 },
            { header: 'COUPONRATE', dataIndex: 'COUPONRATE', width: 100 },
            { header: 'ASKPRICE', dataIndex: 'ASKPRICE', width: 100 }
         ],
        renderTo: 'example-grid',
        width: 1000,
        autoHeight: true,
        title: 'JSON SIMPLE 2'
    }).render();
});

Вот как выглядит мой объект JSON:

{"totalCount":3316,"items":[{"CUSIP":"989701AL1","DESCRIPTION":"ZIONS BANCORPORATIONSB NT 5.65000% 05/15/2014","COUPONRATE":"  5.650","ASKPRICE":"    104.450"}]}

Сетка просто не заполняется, и я вижу, что JSON возвращается мне с сервера.

Мысли?

Ответы [ 3 ]

2 голосов
/ 08 мая 2011

Проблема в том, что вы используете магазин с типом alax / json. Поскольку у вас есть междоменный URL, JSON.

Решение: убедитесь, что тестовые файлы размещены с использованием HTTP из того же домена, и все должно быть в порядке:

   var store = new Ext.data.Store({
        model: 'Bond',
        proxy: {
            type: 'ajax',
            url: 'SOData.json',
            reader: {
                type: 'json',
                root: 'items',
                totalProperty: 'totalCount'
            }
        }
    });
1 голос
/ 08 ноября 2012

попробуйте так

var URLdata = window.location.protocol + "//" + window.location.host + "/" + "bigdata-dashboard" + "/conf/" +"survey.json" ;
      var storedata = new Ext.data.Store({
          fields: ['appeId','survId','location','surveyDate','surveyTime','inputUserId'],
            proxy: {
                type: 'rest',
               url:URLdata,
                reader: {
                    type: 'json',
                    root: 'items',
                   // totalProperty: 'totalCount'
                }
            }
        });
           storedata.load();


        // create the grid
        var grid = new Ext.grid.GridPanel({
            store: storedata,
            columns: [
                {header: "appeId", width: 60, dataIndex: 'appeId', sortable: true},
                {header: "survId", width: 60, dataIndex: 'survId', sortable: true},
                {header: "location", width: 60, dataIndex: 'location', sortable: true},
                {header: "surveyDate", width: 100, dataIndex: 'surveyDate', sortable: true},
                {header: "surveyTime", width: 100, dataIndex: 'surveyTime', sortable: true},
                {header: "inputUserId", width:80, dataIndex: 'inputUserId', sortable: true}
            ],
            renderTo:'example-grid',
            width:470,
            height:200
        });
1 голос
/ 09 июня 2011

вам нужно изменить службу для возврата jsonp и изменить тип магазина на jsonp, что решит проблему,

Пожалуйста, дайте мне знать, если вам нужна дополнительная информация

...