我是流星相当新的,但真的很享受它,这是我第一个被动的应用程序,我正在建设。流星:隐藏或移除元素?什么是最好的方式
我想知道一种方法,可以在用户单击时删除.main
元素,或者更好的方法是删除现有模板(包含主要内容),然后替换为另一个流星模板?像这样的东西在html/js应用程序中会很简单直接(用户点击 - >从dom中删除el),但这里并不清楚。
我只是想了解一些有关最佳实践的见解。
//gallery.html
<template name="gallery">
<div class="main">First run info.... Only on first visit should user see this info.</div>
<div id="gallery">
<img src="{{selectedPhoto.url}}">
</div>
</template>
//gallery.js
firstRun = true;
Template.gallery.events({
'click .main' : function(){
$(".main").fadeOut();
firstRun = false;
}
})
if (Meteor.isClient) {
function showSelectedPhoto(photo){
var container = $('#gallery');
container.fadeOut(1000, function(){
Session.set('selectedPhoto', photo);
Template.gallery.rendered = function(){
var $gallery = $(this.lastNode);
if(!firstRun){
$(".main").css({display:"none"});
console.log("not");
}
setTimeout(function(){
$gallery.fadeIn(1000);
}, 1000)
}
});
}
Deps.autorun(function(){
selectedPhoto = Photos.findOne({active : true});
showSelectedPhoto(selectedPhoto);
});
Meteor.setInterval(function(){
selectedPhoto = Session.get('selectedPhoto');
//some selections happen here for getting photos.
Photos.update({_id: selectedPhoto._id}, { $set: { active: false } });
Photos.update({_id: newPhoto._id}, { $set: { active: true } });
}, 10000);
}
非常感谢。这是完全合理的,并与我如何编写应用程序的其余部分保持一致。再次感谢您的答案和例子! – jeffreynolte
它总是很高兴得到协助:-) –
嗨戈布 - 我正在学习一个新项目的流星,这真的很有帮助!谢谢! –