【问题标题】:How to show EXT js Grid with .log data file?如何使用 .log 数据文件显示 EXT js Grid?
【发布时间】:2016-05-10 05:31:13
【问题描述】:

我有一个 .log 文件。我在 EXT JS 中创建了一个网格示例来显示来自 json 文件(模拟数据)的日志数据。现在我想显示 .log 文件中的网格数据。最好的方法是什么?可以将 .log 文件转换为 .json 文件(通过解析或说 somw 如何)还是有更好/更明智的方法来做同样的事情?

【问题讨论】:

  • 日志文件长什么样?
  • 标准 log4j 日志文件....基于选项卡.. 比如说 aa bb cc dd ee ff gg bb kk bb vv xx ii aa 。 . . .

标签: javascript gridview extjs


【解决方案1】:

我认为您需要通过 Ajax 请求以不同方式获取数据。

// Should work also in newer ExtJS versions
Ext.create('Ext.grid.Panel', {
  renderTo: Ext.getBody(),
  width: 640,
  height: 480,
  store: new Ext.data.ArrayStore({
    fields: ['id', 'val1', 'val2'],
    data: []
  }),
  columns: [{
    dataIndex: 'id',
    text: 'Id'
  }, {
    dataIndex: 'val1',
    text: 'Value #1'
  }, {
    dataIndex: 'val2',
    text: 'Value #2'
  }],
  listeners: {
    afterrender: function(grid) {
      // Do an Ajax request
      Ext.Ajax.request({
        url: 'data1.log',
        // Will go here, because there is no such file...
        // When you provide a file it will be success and you can handle failure differently
        failure: function(response) {
          // responseText will be response.responseText on success
          // this here is only a mock
          var responseText =    "id1\tval1a\tval1b\nid2\tval2a\tval2b\nid3\tval3a\tval3b",
            data = [];

          // Split your data on new lines and iterate
          Ext.each(responseText.split('\n'), function (record) {
            // Create an empty array
            var item = [];
            // Split your new line-split on tab and iterate
            Ext.each(record.split('\t'), function (recordItem) {
                // push to your new data item
                item.push(recordItem);
            });
            // push to your data
            data.push(item);
          });
          // load the store
          grid.store.loadRawData(data);
        }
      });
    }
  }
});

我在 jsfiddle 上提供了一个示例:http://jsfiddle.net/4Lx818ua/

祝你好运。

【讨论】:

    猜你喜欢
    • 2011-11-20
    • 2013-06-13
    • 1970-01-01
    • 2020-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-28
    相关资源
    最近更新 更多