💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
## Template instances 一个模板实例对象代表文档对模板的一次引入。模板实例可以用来获取模板中的HTML元素,还可以给模板实例附加属性,属性会在模板响应式更新中保持,不会丢失。 在好几个地方都可以获取到模板实例对象: 1. 在`created`, `rendered`和 `destroyed`模板回调中,this指向模板实例 2. 事件处理器的第二个参数 3. 在Helper中,通过[`Template.instance()`](#template_instance)获取模板实例 你可以选择给模板实例附加属性,来跟踪模板相关的状态。例如,当使用Google Maps API 时,你可以附加`map`对象到当前模板实例,这样就可以在Helper和事件处理器中引用`map`对象。用[`onCreated`](#template_onCreated) 和 [`onDestroyed`](#template_onDestroyed)回调函数来执行初始化或清理工作。 ### [_template_.findAll(selector)](#/basic/Blaze-TemplateInstance-findAll) Client Find all elements matching `selector` in this template instance. #### Arguments selector String The CSS selector to match, scoped to the template contents. `template.findAll`返回一个符合`selector`的DOM元素数组。也可以使用`template.$`,它的工作方式和JQuery的`$`函数一样,但是只返回`template`内部的元素。 ### [_template_.find(selector)](#/basic/Blaze-TemplateInstance-find) Client Find one element matching `selector` in this template instance. #### Arguments selector String The CSS selector to match, scoped to the template contents. `find`类似`findAll`但是只返回找到的第一个元素。和`findAll`一样,`find`只返回模板内部的元素。