1

我有以下模板:

<template name="datatable">
  <table class="table table-hover">
    <thead>
      <tr>
        <th>Path</th>
        <th>Average</th>
      </tr>
    </thead>
    <tbody>
      {{#each entries}}
        <tr>
          <td>{{path}}</td>
          <td>{{avg}}</td>
        </tr>
      {{/each}}
    </tbody>
  </table>
</template>

条目填充有:

Template.datatable.entries = ->
  Metrics.find( { metric: 'mean' }, { fields: { path: 1, avg: 1 }, sort: { avg: -1 }, limit: 10 })

两个问题:

1)当我刷新页面时,我可以看到表格行变化很快,直到它显示 10 的排序列表。就好像客户端正在接收所有数据并显示和排序一样。我想我会得到的是客户端只从服务器接收 10 行。

2)当服务器更新集合时,客户端冻结,直到服务器完成更新。

我该如何解决这两个问题?

4

1 回答 1

2
  1. You are partially right. The client is processing the data as it comes from the server. But it doesn't happen when you call find, but when subscribe is called. When you refresh the page, a new connection to the server is created as well as a new subscription. You can use subscription's ready() to wait for initial data to arrive. See docs. If you don't want to handle the subscription state by yourself, IronRouter has a builtin way of waiting for the data to arrive (if using a router is not an overkill)

  2. 听起来很奇怪。在服务器将数据发送给客户端之前,客户端应该无法告诉服务器正在更新。发生这种情况时,您应该体验 #1 中的行为。我猜想要么您向客户端发送了太多数据,需要时间进行排序,要么您正在更新大量数据。更多细节或活生生的例子可能会有所帮助。

于 2013-09-05T04:48:56.463 回答