2

我有一个看起来像这样的模板:

<template name="foo">
  <div id="wrapper" style="overflow: hidden">
    <div id="content" style="margin-top: -{{contentHeight}}px">
      {{content}}
    </div>
    <button id="toggle">Show/Hide Content</button>
  </div>
</template>

where{{contentHeight}}是计算 高度的助手,#content单击切换按钮会#content通过为其边距设置动画来向上/向下滑动。

问题是,当我对 进行数据库更新时foo#contentstyle属性被重置为新contentHeight值,将其隐藏。我不希望 Meteor 在渲染后触摸元素,但即使给它一个唯一的 ID 也不能阻止它;正如文档所说:

Meteor 将保留 [具有唯一名称/ID 的元素],即使它们的封闭模板被重新渲染,但仍会更新其子级并复制任何属性更改。

(强调我的。)那么最好的方法是什么?如何在style渲染模板时设置元素,然后防止 Meteor 修改属性?

4

1 回答 1

0

您是否尝试过类似的方法:

<div id="content" {{contentHeightStyle}}>

Template.foo.contentHeightStyle = function() {
  if (!this._contentHeightStyleCalculated) {
    this._contentHeightStyleCalculated = true;
    return 'style="..."';
  }
}
于 2012-06-17T07:57:54.210 回答