流星';s Session.set是否导致引导模式重复?
我使用的是流星0.6.2.1 我刚刚在调用Meteor的Session.set()时遇到了引导模式的一个奇怪问题 我想显示一个简单的模式对话框,并在用户单击模板实例时更新其中的一些数据 我将引导模式示例复制到.html文件:流星';s Session.set是否导致引导模式重复?,session,twitter-bootstrap,duplicates,modal-dialog,meteor,Session,Twitter Bootstrap,Duplicates,Modal Dialog,Meteor,我使用的是流星0.6.2.1 我刚刚在调用Meteor的Session.set()时遇到了引导模式的一个奇怪问题 我想显示一个简单的模式对话框,并在用户单击模板实例时更新其中的一些数据 我将引导模式示例复制到.html文件: <body> {{> hello}} {{> alert}} </body> <template name="hello"> <h1>Hel
<body>
{{> hello}}
{{> alert}}
</body>
<template name="hello">
<h1>Hello World!</h1>
{{greeting}}
<input type="button" value="Click" />
<br/>
<!-- Button to trigger modal -->
<a href="#myModal" role="button" class="btn" data-toggle="modal">Launch demo modal</a>
</template>
<template name="alert">
<!-- Modal -->
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Modal header</h3>
</div>
<div class="modal-body">
<p>One fine body…</p>
<p>data = {{data}}</p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary">Save changes</button>
</div>
</div>
</template>
我使用chrome对其进行调试,并在单击按钮时看到模态元素将重复
我的代码怎么了?我不能100%确定为什么会发生这种情况,但我相信这与JS代码中保存的模式节点(引导)的引用有关 为了解决这个问题,我补充道:
Template.alert.preserve(["#myModal"]);
来自流星:
保存在替换DOM的各种情况下都很有用
具有相同或修改的元素的元素将不具有相同的
效果与保留原始图元相同。这些措施包括:
- 输入文本字段和其他表单控件
- 带有CSS动画的元素
- Iframes
- JavaScript代码中保留引用的节点
谢谢你。这帮了大忙!
Template.alert.preserve(["#myModal"]);