2016-05-10 24 views
0

我有一個.log文件。我在EXT JS中創建了一個網格示例來顯示來自json文件(模擬數據)的日誌數據。現在我想顯示.log文件中的網格數據。什麼是最好的辦法呢?可以將.log文件轉換爲.json文件(通過解析或者說somw如何)或者是否有更好/合理的方法來做同樣的事情?如何使用.log數據文件顯示EXT js Grid?

+0

日誌文件是怎樣的? –

+0

標準log4j日誌文件....基於標籤.. 說, aa bb cc dd ee ff gg bb kk bb vv xx ii aa 。 。 。 。 – souro

回答

0

我想你需要通過Ajax請求以不同的方式獲取數據。 http://jsfiddle.net/4Lx818ua/

好運:

// 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提供了一個示例。