我对Meteor很新,但真的很喜欢它,这是我建立的第一个被动应用程序.
我想知道一种方法,我可以.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 : …Run Code Online (Sandbox Code Playgroud) 我正在使用Meteor与AutoForm和铁路由器.
我有一个autoform用于插入记录,我想重定向到另一个页面以在成功插入后查看记录. 什么是普遍接受的方式?
如果我使用标准的autoform插件,如:
{{#autoForm collection="Articles" id="articleSubmit" type="insert"}}
Run Code Online (Sandbox Code Playgroud)
我看不出如何重定向?
如果我使用'method'类型,如下所示:
{{#autoForm collection="Articles" id="articleSubmit" type="method"}}
Run Code Online (Sandbox Code Playgroud)
然后我必须编写一个不特别干的插入方法.
我有一个简单的before_save转换,并了解到phoenix使用Ecto changest来完成这项任务.
我的Stage模型有一个position属性,默认为current maximum + 1如此尝试实现如下:
舞台模型:
def changeset(struct, params \\ %{}) do
struct
|> cast(params, @required_fields, @optional_fields)
|> validate_required([:name])
|> set_position
end
defp set_position(current_changeset) do
# get current max position from db
max_position = Repo.one(
from s in Stage,
select: fragment("COALESCE(MAX(?),0)", s.position)
)
case current_changeset do
%Ecto.Changeset{valid?: true} ->
put_change(current_changeset, :position, max_position+1)
_ ->
current_changeset
end
end
Run Code Online (Sandbox Code Playgroud)
在逐个插入记录时工作正常但在批量插入时失败; 例如在下面的seed文件中.
种子
alias MyApp.{Repo, Post}
[
%{name: "Requirements"},
%{name: "Quotation"},
%{name: "Development"},
%{name: …Run Code Online (Sandbox Code Playgroud)