Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Meteor 从currentView获取jQuery元素_Meteor_Meteor Blaze - Fatal编程技术网

Meteor 从currentView获取jQuery元素

Meteor 从currentView获取jQuery元素,meteor,meteor-blaze,Meteor,Meteor Blaze,在api文档中,可以使用选择器找到当前模板实例视图,前提是选择器的属性提前已知 template.findAll(selector) template.$(selector) 我还知道可以从Blaze.currentView或template.view获取视图,但是可以从Blaze.currentView或template.view获取jQuery元素吗?之所以要这样做,是因为我事先不知道模板实例的属性。您可以使用以下方法访问绑定到模板实例或视图的第一个和最后一个DOM节点: 模板实例上的f

在api文档中,可以使用选择器找到当前模板实例视图,前提是选择器的属性提前已知

template.findAll(selector)
template.$(selector)

我还知道可以从Blaze.currentView或template.view获取视图,但是可以从Blaze.currentView或template.view获取jQuery元素吗?之所以要这样做,是因为我事先不知道模板实例的属性。

您可以使用以下方法访问绑定到模板实例或视图的第一个和最后一个DOM节点:

  • 模板实例上的firstNode和lastNode属性
  • Blaze.View
    实例上的firstNode()和lastNode()方法
检索DOM元素时,可以像往常一样使用
$
函数从中构建jQuery对象。 HTML


查看
Blaze。在这里查看
完整文档:

我想我需要更多关于您到底想做什么的信息。我不确定您所说的“视图的jQuery元素”是什么意思。
<template name="test">
  <p>First paragraph</p>
  <p>Last paragraph</p>
</template>
Template.test.rendered=function(){
  var $firstNode=$(this.firstNode);
  $firstNode.css("backgroundColor","red");
  //
  var $lastNode=$(this.view.lastNode());
  $lastNode.css("backgroundColor","green");
};