Javascript 如果标记嵌套在{{#with}}块中,Meteor-DOM查询将不起作用

Javascript 如果标记嵌套在{{#with}}块中,Meteor-DOM查询将不起作用,javascript,jquery,meteor,Javascript,Jquery,Meteor,HTML <template name="formExample"> <form> {{#with formData}} <input type="text" class="example"> {{/with}} </form> </template> <template name="formExample"> <form> {{#with formData}}

HTML

<template name="formExample">
  <form>
  {{#with formData}}

    <input type="text" class="example">

  {{/with}}
  </form>
</template>
<template name="formExample">
  <form>
    {{#with formData}}
      {{> formExampleItems}}    
    {{/with}}
  </form>
</template>

<template name="forExampleItems">
  <input type="text" class="example">
</template>

如何使用逻辑块中的代码有效地查询DOM、init函数等?我希望使用
模板。$
模板。查找
方法来工作。

您在哪里设置
表单数据?
我试过你的例子,似乎很管用


测试:

在哪里设置
formData
? 我试过你的例子,似乎很管用


测试:

我发现有时它也能工作,所以这可能是一个更好的解决方案

HTML

<template name="formExample">
  <form>
  {{#with formData}}

    <input type="text" class="example">

  {{/with}}
  </form>
</template>
<template name="formExample">
  <form>
    {{#with formData}}
      {{> formExampleItems}}    
    {{/with}}
  </form>
</template>

<template name="forExampleItems">
  <input type="text" class="example">
</template>

我发现有时候它也能起作用,所以也许这是一个更好的解决方案

HTML

<template name="formExample">
  <form>
  {{#with formData}}

    <input type="text" class="example">

  {{/with}}
  </form>
</template>
<template name="formExample">
  <form>
    {{#with formData}}
      {{> formExampleItems}}    
    {{/with}}
  </form>
</template>

<template name="forExampleItems">
  <input type="text" class="example">
</template>

抱歉,编辑以澄清。通过帮助程序从集合中获取
formData
。有时候,它也对我有用。我怀疑是因为async。也许你可以尝试用$(function(){})这样的东西包装它;...左右这可能与您的问题类似:-您是否可以尝试将setTimeout设置为0 ms,并检查是否仍然出现这种奇怪的行为?是否仍然使用setTimeout和自调用匿名函数。很奇怪,但考虑到这种情况有多普遍,必须有一个解决方案来澄清。通过帮助程序从集合中获取
formData
。有时候,它也对我有用。我怀疑是因为async。也许你可以尝试用$(function(){})这样的东西包装它;...左右这可能与您的问题类似:-您是否可以尝试将setTimeout设置为0 ms,并检查是否仍然出现这种奇怪的行为?是否仍然使用setTimeout和自调用匿名函数。很奇怪,但考虑到这种情况的普遍性,必须有一个解决方案