3

Railsアプリの上に構築され、Ember Dataを操作し、1つのエンティティタイプのみを表示、作成、サーバーに永続化する、非常にシンプルなEmberアプリを作成しました。最新のツール(Ember v1.0.0-pre.4-134-gaafb5eb)を備えたすべて。

しかし、私が遭遇した非常に奇妙な問題があります。私のアプリには、エンティティリスト(インデックス)と新しいエンティティを作成するためのフォームの2つのビューがあります。インデックスを直接入力すると、すべてOKと表示されます。しかし、他のビューに移動してからリストに戻ると、ビューは再度レンダリングされません。どこに問題があるのでしょうか?

新しいEmberルーターを使用していることが原因である可能性があります(おそらく正しくありません)。だから私はここにアプリの重要な部分を(私の観点から)貼り付けています:

ルーター:

App.Router.map(function() {
  this.resource('bands', function() {
    this.route('new');
  });
});

App.IndexRoute = Ember.Route.extend({
  redirect: function() {
    this.transitionTo('bands');
  }
});

App.BandsRoute = Ember.Route.extend({
    model: function() {
        return App.Band.find();
    }
});

App.BandsNewRoute = Ember.Route.extend({
    renderTemplate : function(){
        this.render('bands_new',{
            into:'application'
        });
    }
});

リストに戻るリンク-これは機能しません:

App.BandsNewController = Em.ArrayController.extend({
    cancel: function() {
        this.transitionTo('bands');
    }
});

ここでアプリ全体を見てください:https
://github.com/pavelsmolka/roommating (素晴らしいhttps://github.com/dgeb/ember_data_exampleに大きく影響を受けています)

信じられませんが、Ember自体のバグでしょうか?

4

1 に答える 1

4

BandsNewRouteでの「レンダリング」呼び出しが混乱していると思います。Emberのデフォルトを使用して、状況をさらに改善してみてください。だから私はこれを行うためにあなたのアプリをリファクタリングします:

(作業フィドル: http: //jsfiddle.net/andremalan/DVbUY/

独自のレンダリングを作成する代わりに、「bands」テンプレート(必要に応じて{{outlet}}を除いて完全に空にすることができます)と「bands.index」テンプレートを作成するだけです。

<script type="text/x-handlebars" data-template-name="application">
    {{outlet}}
</script>


<script type="text/x-handlebars" data-template-name="bands/index">
    <h2>Bands Index</h2>
    {{#linkTo bands.new}}New Band{{/linkTo}}
</script>

<script type="text/x-handlebars" data-template-name="bands">
    <h1>Bands</h1>
    <p>
      {{#linkTo index}}Start Again{{/linkTo}}
      {{#linkTo bands.new}}New Band{{/linkTo}}
    </p>
    {{outlet}}
</script>

<script type="text/x-handlebars" data-template-name="bands/new">
    I'm in new band!
    <a {{action "cancel"}}>Cancel</a>
</script>

あなたのルートもこの方法で本当にきれいにきれいになります:

App.Router.map(function() {
    this.resource('bands', function() {
        this.route('new');
    });
});

App.IndexRoute = Ember.Route.extend({
  redirect: function() {
    this.transitionTo('bands');
  }
});


App.BandsNewController = Ember.Controller.extend({
    cancel: function() {
        this.transitionTo('bands');
    }
});

お役に立てば幸いです。

于 2013-02-10T12:20:32.963 に答える