There are " + highScoring.count() + " 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 invokes callbacks when the result of the query changes. The callbacks receive the entire contents of the document that was affected, as well as its old contents, if applicable. If you only need to receive the fields that changed, see [`observeChanges`](#observe_changes). `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}} If value is a scalar, then 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: {{dstache}}! 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. }} {{dstache}}#each posts}} {{dstache}}> postItem }} {{dstache}}/each}} {{! }}template>There are " + Players.find({online: true}).count() + " players online.
"; }); document.body.appendChild(frag); // Server side: find all players that have been idle for a while, // and mark them as offline. The count on the screen will // automatically update on all clients. Players.update({idleTime: {$gt: 30}}, {$set: {online: false}}); {{> api_box renderList}} Creates a `DocumentFragment` that automatically updates as the results of a database query change. Most Meteor apps use `{{dstache}}#each}}` in a template instead of calling this directly. `renderList` is more efficient than using `Meteor.render` to render HTML for a list of documents. For example, if a new document is created in the database that matches the query, a new item will be rendered and inserted at the appropriate place in the DOM without re-rendering the other elements. Similarly, if a document changes position in a sorted query, the DOM nodes will simply be moved and not re-rendered. `docFunc` is called as needed to generate HTML for each document. If you provide `elseFunc`, then whenever the query returns no results, it will be called to render alternate content. You might use this to show a message like "No records match your query." Each call to `docFunc` or `elseFunc` is run in its own reactive computation so that if it has other external data dependencies, it will be individually re-run when the data changes. 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. Display the selected post differently. var frag = Meteor.renderList( Posts.find({tags: "frontpage"}), function(post) { var style = Session.equals("selectedId", post._id) ? "selected" : ""; // A real app would need to quote/sanitize post.name return 'click
"}}
Mouse click on any element, including a link, button, form control, or div.
Use `preventDefault()` to prevent a clicked link from being followed.
Some ways of activating an element from the keyboard also fire `click`.
{{/dtdd}}
{{#dtdd "dblclick
"}}
Double-click.
{{/dtdd}}
{{#dtdd "focus, blur
"}}
A text input field or other form control gains or loses focus. You
can make any element focusable by giving it a `tabindex` property.
Browsers differ on whether links, checkboxes, and radio buttons are
natively focusable. These events do not bubble.
{{/dtdd}}
{{#dtdd "change
"}}
A checkbox or radio button changes state. For text fields, use
`blur` or key events to respond to changes.
{{/dtdd}}
{{#dtdd "mouseenter, mouseleave
"}} The pointer enters or
leaves the bounds of an element. These events do not bubble.
{{/dtdd}}
{{#dtdd "mousedown, mouseup
"}}
The mouse button is newly down or up.
{{/dtdd}}
{{#dtdd "keydown, keypress, keyup
"}}
The user presses a keyboard key. `keypress` is most useful for
catching typing in text fields, while `keydown` and `keyup` can be
used for arrow keys or modifier keys.
{{/dtdd}}
null
on error.null
error
callback parameter.