1

ハンドルバー条件内に表示するインライン テンプレートを使用してビューを取得しようとしています。私のアプリケーション コードでは、別のルートに移動してから再び戻ると表示されます。フィドルでは、ビューに関するエラーが発生します。

JSFiddle

<script type="text/x-handlebars" data-template-name="application">
    <h1>If you click that button, I might say 'Hello!'</h1>
        <button {{action 'click_me'}}>Click me</button>
        {{#if controller.new_visible}}
            {{#view App.MyView}}
                    Hello!            {{/view}}
        {{/if}}
</script>


var App = Ember.Application.create();

App.MyView = Ember.View.extend({});

App.ApplicationController = Ember.Controller.extend({
    new_visible: false,
    actions: {
        click_me: function() {
            alert('You clicked me!');
            this.set('new_visible',true);
        }
    }
});

App.ApplicationView = Ember.View.extend({
  templateName: 'application'
});

App.Router = Ember.Router.extend({
  root: Ember.Route.extend({
    index: Ember.Route.extend({
      route: '/'
    })
  })
});

私は何を間違っていますか?

4

1 に答える 1

0

Appはグローバルである必要があります。JavaScript ログを確認すると、ハンドルバー ビュー ヘルパーが という名前のビューを見つけられないことがわかりますApp.MyView。これAppは、 がローカルで宣言されているため、テンプレートがアクセスできないためです。App定義を次のように変更します。

window.App = Ember.Application.create();

また、ルーターを拡張する必要はありません。マップだけ使えます。例えば

App.Router.map(function(){
  this.route('index', {path: '/'});
});

これが実際の JSFiddle です: http://jsfiddle.net/PkT8x/420/

于 2013-10-18T05:19:39.650 に答える