小编Nim*_*mir的帖子

Meteor:隐藏还是删除元素?什么是最好的方法

我对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)

javascript dom handlebars.js meteor

6
推荐指数
1
解决办法
9523
查看次数

使用AutoForm和Iron Router在Meteor上检查插入后成功重定向提交表单的标准模式?

我正在使用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)

然后我必须编写一个不特别干的插入方法.

javascript meteor iron-router meteor-autoform

4
推荐指数
1
解决办法
1899
查看次数

如何将Ecto变换集设计为真正的before_save回调

我有一个简单的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)

elixir ecto phoenix-framework

1
推荐指数
1
解决办法
315
查看次数