4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ember.jsで複数種類のポップアップを表示する

Last updated at Posted at 2014-06-10

明細の中の編集ポップアップのイメージ
1種類のデータだが、データの状態に応じて、テンプレートを変更したい

ポップアップのテンプレートを複数用意する

popup1.hbs
<div id='editNoNaka'>1</div>
popup2.hbs
<div id='editNoNaka'>2</div>

ポップアップ表示元画面にコンテナを用意する

ControllerにContainerViewを用意する

mainController.js
App.MainController = Ember.ArrayController.extend({
    editContainer: Ember.ContainerView.create(),
	...

テンプレート内でそのContainerViewをいれておく

main.hbs
    <div class="edit">
        {{view editContainer}}
    </div>

呼び出し処理

アクション(引数付き)を用意し、その中でコンテナに対しViewのCreateを行う
Viewに対して、templateNameにアクション引数を渡すことで、テンプレートを切り替える

mainController.js
App.MainController = Ember.ArrayController.extend({
	...

	actions: {
		openEdit: function(hoge) {
			this.get('editContainer').removeAllChildren();
			this.get('editContainer').pushObject(App.EditPopupView.create({templateName: hoge}));
        },

アクションを呼び出すボタンを用意する
その引数としてテンプレート名を渡す

main.hbs
    <button {{action openEdit 'popup1'}}>green</button>
    <button {{action openEdit 'popup2'}}>red</button>

表示処理

Viewの初期表示、didInsertElementで、jQueryでうまく表示する
View自身は

edit_popup_view.js
App. App.EditPopupView = mber.View.extend({
    templateName: '',
    didInsertElement: function() {
        this.$('#editNoNaka').show();
    },
	...
});
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?