connected
(the connection is up and
running), connecting
(disconnected and trying to open a
new connection), and waiting
(failed to connect and
waiting to try to reconnect).retry_time - (new Date()).getTime()
. This key will
be set only when status
is waiting
.
There are " + high_scoring.length + " posts with " + "scores greater than 10
"); }); document.body.appendChild(frag); Unlike the other functions, `count` registers a dependency only on the number of matching documents. (Updates that just change or reorder the documents in the result set will not trigger a recomputation.) {{> api_box cursor_rewind}} The `forEach`, `map`, or `fetch` methods can only be called once on a cursor. To access the data in a cursor more than once, use `rewind` to reset the cursor. {{> api_box cursor_observe}} Establishes a *live query* that notifies callbacks on any change to the query result. `callbacks` may have the following functions as properties:We've always been at war with " + Session.get("enemy") + "
"); }); // Page will say "We've always been at war with Eastasia" document.body.append(frag); // Page will change to say "We've always been at war with Eurasia" Session.set("enemy", "Eurasia"); {{> api_box equals}} These two expressions do the same thing: (1) Session.get("key") === value (2) Session.equals("key", value) ... but the second one is always better. It triggers fewer invalidations (template redraws), making your program more efficient. Example: // Show a dynamically updating list of items. Let the user click on an // item to select it. The selected item is given a CSS class so it // can be rendered differently. var frag = Meteor.ui.renderList(Posts, { render: function (post) { var cls = Session.equals("selected_post", post._id) ? "selected" : ""; return $("collection.update
](#pkg_minimongo_update), etc.)
The auto-updating elements are returned as a `DocumentFragment`. Simply
insert this `DocumentFragment` anywhere in the DOM you like. Its
elements will update themselves automatically until they are taken
offscreen — specifically, until [`Meteor.flush`](#meteor_flush) is called
when the elements are not children of `document`.
`events` lets you quickly hook up some event handlers to
the DOM nodes. If you provide `event_data`, it will be
passed to event handlers in `this`.
`Meteor.ui.render` may be called recursively (that
is, `render_func` can call `Meteor.ui.render`.) If
that happens, each invocation of `render` works
independently — an change to a dependency of the
inner `render_func` will (correctly) not cause the
outer `render_func` to be recomputed.
Example:
// Show the number of users online.
var frag = Meteor.ui.render(function () {
return $("There are " + Users.find({online: true}).length + " users online.
"); }); document.body.appendChild(frag); // Find all users that have been idle for a while, and mark them as // offline. The count on the screen will automatically update. Users.update({idleTime: {$gt: 30}}, {online: false}); // Show a counter, and let the user click to increase or decrease it. Session.set("counter", 0); var frag = Meteor.ui.render(function () { return $('collection.find().observe()
](#observe).
It calls a render function repeatedly for each document in a
collection that matches a query.
If you attach event handlers, then when they are triggered, they
will receive the document in `this`.
Returns a `DocumentFragment` with the same semantics as in
[`Meteor.ui.render`](#render) — insert it
anywhere, it will automatically update itself, make sure it's on the
page before the next time you
call [`Meteor.flush`](#meteor_flush).
Example:
// List the titles of all of the posts that have the tag
// "frontpage". Keep the list updated as new posts are made, as tags
// change, etc. Let the user click a post to select it.
Session.set("selected", null);
var frag = Meteor.ui.renderList(Posts, {
render: function (post) {
var style = Session.equals("selected", post._id) ? "selected" : "";
// A real app would need to quote/sanitize post._name
return $('