2

有人可以向我解释为什么这不起作用吗?没有任何错误。

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 从服务器返回给我。

想法?

4

3 回答 3

2

试试这个方法

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
        });
于 2012-11-08T12:26:27.537 回答
2

问题在于您使用的是 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'
            }
        }
    });
于 2011-05-08T11:42:34.417 回答
1

您需要更改服务以返回 jsonp 并将存储类型更改为 jsonp,这将解决问题,

如果您需要更多信息,请告诉我

于 2011-06-09T17:08:43.353 回答