将数据加载到slickgrid中

时间:2012-11-28 14:49:10

标签: javascript jquery slickgrid

我正在尝试使用这个在SO中找到的加载模式: Load slickgrid

话虽如此,我实际显示网格时遇到了一些麻烦。 我一直得到“未被捕获的ReferenceError:未定义loadGrid”。我不确定选项var,我怀疑我正在初始化它。

任何帮助都将不胜感激。

    
   function loadGrid () {
    var data =  [
        ['3m Co',                               71.72, 0.02,  0.03,  '9/1 12:00am'],
        ['Alcoa Inc',                           29.01, 0.42,  1.47,  '9/1 12:00am'],
        ['Altria Group Inc',                    83.81, 0.28,  0.34,  '9/1 12:00am'],
        ['American Express Company',            52.55, 0.01,  0.02,  '9/1 12:00am'],
        ['American International Group, Inc.',  64.13, 0.31,  0.49,  '9/1 12:00am'],
        ['AT&T Inc.',                           31.61, -0.48, -1.54, '9/1 12:00am'],
        ['Boeing Co.',                          75.43, 0.53,  0.71,  '9/1 12:00am'],
        ['Caterpillar Inc.',                    67.27, 0.92,  1.39,  '9/1 12:00am'],
        ['Citigroup, Inc.',                     49.37, 0.02,  0.04,  '9/1 12:00am'],
        ['E.I. du Pont de Nemours and Company', 40.48, 0.51,  1.28,  '9/1 12:00am'],
        ['Exxon Mobil Corp',                    68.1,  -0.43, -0.64, '9/1 12:00am'],
        ['General Electric Company',            34.14, -0.08, -0.23, '9/1 12:00am'],
        ['General Motors Corporation',          30.27, 1.09,  3.74,  '9/1 12:00am'],
        ['Hewlett-Packard Co.',                 36.53, -0.03, -0.08, '9/1 12:00am'],
        ['Honeywell Intl Inc',                  38.77, 0.05,  0.13,  '9/1 12:00am'],
        ['Intel Corporation',                   19.88, 0.31,  1.58,  '9/1 12:00am'],
        ['International Business Machines',     81.41, 0.44,  0.54,  '9/1 12:00am'],
        ['Johnson & Johnson',                   64.72, 0.06,  0.09,  '9/1 12:00am'],
        ['JP Morgan & Chase & Co',              45.73, 0.07,  0.15,  '9/1 12:00am'],

    ];

    var options = {'autoHeight:true'};
    var columns = ['company','price','change','pctChange','lastChange'];
    var grid;
    // ... code to get data

    // ... code to get column data/settings

    // ... code to get option data

    $(function () {
    if (grid) {
    grid.setOptions(options);
    grid.setColumns(columns);
    grid.setData(data);
    grid.render();
        } else {
        grid = new Slick.Grid('#trade-reg-trade-info-table', data, columns,options);

                }

     $('#trade-reg-trade-info-table').show();   
    });
    }

谢谢你,现在我已经纠正了它,我仍然得到同样的错误。有任何想法吗?

1 个答案:

答案 0 :(得分:1)

new Slick.Grid('#trade-reg-trade-info-table"

您使用单引号打开并尝试以双引号结束。

{
  'company':    'JP Morgan & Chase & Co',
  'price':      45.73,
  'change':     0.07,
  'pctChange':  0.15,
  'lastChange': '9/1 12:00am'
}