【问题标题】:display data from io.socket in Slickgrid在 Slickgrid 中显示来自 io.socket 的数据
【发布时间】:2015-09-29 23:05:54
【问题描述】:

我从 io.socket 接收数据,我想将数据放入对象数组中,以便可以在 slickgrid 中显示。由于某种原因,信息中推送的数据为空。有人可以帮我解决这个问题吗?

谢谢!!

<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <title>SlickGrid</title>
  <link rel="stylesheet" href="/slick.grid.css" type="text/css"/>
  <link rel="stylesheet" href="/css/smoothness/jquery-ui-1.8.16.custom.css" type="text/css"/>
  <link rel="stylesheet" href="/examples/examples.css" type="text/css"/>
</head>
<body>
<table width="100%">
  <tr>
    <td valign="top" width="50%">
      <div id="myGrid" style="width:600px;height:500px;"></div>
    </td>
    <td valign="top">
      <h2>Demonstrates:</h2>
      <ul>
        <li>basic grid with minimal configurations</li>
      </ul>
        <h2>View Source:</h2>
        <ul>
            <li><A href="https://github.com/mleibman/SlickGrid/blob/gh-pages/examples/example1-simple.html" target="_sourcewindow"> View the source for this example on Github</a></li>
        </ul>
    </td>
  </tr>
</table>

<script src="/lib/jquery-1.7.min.js"></script>
<script src="/lib/jquery.event.drag-2.2.js"></script>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script src="/slick.core.js"></script>
<script src="./slick.grid.js"></script>

<script>
  var grid;
  var info;
  var info= [];
  var columns = [
    {id: "completed", name: "completed", field: "completed"},
    {id: "createdAt", name: "createdAt", field: "createdAt"},
    {id: "id", name: "id", field: "id"},
    {id: "title", name: "title", field: "title"},
  ];

  var options = {
    enableCellNavigation: true,
    enableColumnReorder: false
  };


  jQuery(function($){
    var socket = io.connect();

    socket.on('new message', function(data){

      $.each(data, function(idx, obj) {
        info.push(obj);
    });
  })
});

grid = new Slick.Grid("#myGrid", info, columns, options);


</script>
</body>
</html>

【问题讨论】:

    标签: socket.io slickgrid


    【解决方案1】:

    当你更新 slickgrid 后面的数据时,你需要告诉网格用新数据重绘:

      socket.on('new message', function(data){
        $.each(data, function(idx, obj) {
          info.push(obj);
        });
        grid.invalidate(); // not 100% sure this is needed....
        grid.render();
      })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-13
      • 2013-03-29
      • 2013-05-01
      • 1970-01-01
      • 2021-10-03
      • 2015-02-03
      • 1970-01-01
      • 2021-10-30
      相关资源
      最近更新 更多