什么是游标? [英] What is cursor?

查看:58
本文介绍了什么是游标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

发现流星中,

posts: function() {
  return Posts.find();
}

被使用了,不是这个:

posts: function() {
  return Posts.find().fetch();
}

我尝试了下面的功能,它也有效,并且可以实时更新.

I tried function below, it also works, and can realtime update.

游标究竟是什么?以及以上两个功能有什么不同?

What is cursor exactly? And What is the different of above two functions?

推荐答案

Meteor 游标就像文档数组的惰性版本.

The Meteor cursor is like a lazy version of the array of documents.

它旨在迭代查询的结果,而不实际加载每个文档,直到实际请求它们或光标位于包含文档的位置.

It's designed to iterate through the results of a query while not actually loading each of the documents until they are actually requested or the cursor is at the position containing the document.

最好将查询结果视为一本书.如果您使用 .fetch() ,即使您没有阅读它们,也会打印所有页面.

Its better to think of the results of the query as a book. If you use .fetch() all the pages are printed even though you're not reading them.

光标会在您阅读时打印页面.

The cursor prints pages as you're reading them.

此外,光标还有一些与 Blaze 相关的增强功能.内容的呈现频率较低,因为文档更改中的微小细节能够自行更改 DOM 部分,而无需重新创建整个对象.与 JavaScript 对象数组相比,Blaze 与光标交互更容易.

Additionally the cursor has several enhancements with regards to Blaze. Content is rendered less often as minute details in a document's change are able to change the DOM section on its own, without recreating an entire object. It's easier for Blaze to interact with the cursor than an array of Javascript objects.

另外一个游标可以被观察到,一个普通的Javascript对象数组不能

Additionally a cursor can be observed, a plain array of Javascript object's can't

TLDR;Cursor 就像一个对象数组,但设计得更高效 &稍微扩展了一些功能.

TLDR; Cursor is just like an array of objects, but designed to be more efficient & is slightly more extended with features.

这篇关于什么是游标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆