`object:selected`事件两次射击

时间:2016-04-18 07:13:39

标签: javascript fabricjs

我正在使用JavaScriptfabricJs,我有这个事件,

canvas.on('object:selected', onObjectSelected);

function onObjectSelected() {
    console.log(arguments.callee.caller.toString());
    canvas.getActiveObject().set({
        opacity: 0.7
    });
}

当我安慰函数onObjectSelected时,我可以看到它的两次调用。

我也试过了,

stopPropagation
preventDefault
cancelBubble

但不行。我在删除后尝试了

canvas.getActiveObject().set({
    opacity: 0.7
});

工作,这是什么原因?

1 个答案:

答案 0 :(得分:2)

你有没有括号的尝试过,像这样吗?

class UsersController < ApplicationController
  before_filter :save_login_state, :only => [:new, :create]

  def index
    @user = User.all
  end

  def new
      #Signup Form
      @user = User.new     
  end

  def show
    redirect_to(:controller => 'sessions', :action => 'login')
    flash[:notice] = "Successful!"
    flash[:color]= "valid"
  end

  def edit
    @user = User.find(params[:id])

  end

  def update
    @user = User.find(params[:id])

    if @user.update(user_params)
        redirect_to @user
    else
        render 'edit'
    end
  end

   def create
        @user = User.new(user_params)
        if @user.save

            redirect_to(:action => 'login')
        else
            flash[:notice] = "Form is invalid"
            flash[:color]= "invalid"
            render "new"
        end 

    end
  private
  def user_params
    params.require(:user).permit(:email, :password, :password_confirmation, :ime, :prezime, :adresa)
  end
end