1

アカウント、プロジェクト、およびタスク用のemberjsモデル/コントローラー/ビューがあり、アカウントを介してプロジェクトとタスクへのアクセスをスコープしたい場合、emberjsでそれを行うにはどうすればよいですか。'init'の使用を検討していますが、他のすべてのプロパティが設定された後に'init関数'が呼び出されるため、currentUserを取得できるか、デフォルトのcurrentUserを作成して、すべてのemberに関連付けることができるかどうかわかりません。App名前空間内に作成されているオブジェクトインスタンス。

たとえば、emberjsでこれがある場合

App = Ember.Application.create({

  init: function() {
    this._super();
    this.setCurrentUser();
    //console.log(this.get("setCurrentUser")
  },

  setCurrentUser: function(json) {
    this.store.load(this.User, json);
    this.set('currentUser', this.User.find(json['id']));
  }
});

上記のemberjsコードは、App名前空間のいずれかの部分(App.projectなど)にアクセスするたびに、currentUserが最初に検索されることを意味します。これにより、プロジェクトのスコープがUserになります

明確にするために、たとえばレールでは、次のようにスコープアクセスを実行します。

   #account-scope in Rails?
  class ApplicationController < ActionController::Base
    def current_account
      @current_account ||= current_user && current_user.account
    end
  end

  #An imagined ProjectsController showing scoped access of project through account
  @projects = current_account.projects
  @project = current_account.projects.find(params[:id])

あなたの洞察に感謝します。

4

0 に答える 0