1

私はうまく機能する既存のEmberアプリを持っています。ユーザーが追加情報を表示できるようにするには、アプリに新しいサブルートを追加する必要があります。私の現在のルートは次のようになります。

Social.Router.map(function() {
    this.resource('accounts',  { path: '/accounts' }, function(){
        this.resource('account', { path: ':account_id'});
    });
});

次の URL で

#/accounts/56/

追加したいルートは次のとおりです。

#/accounts/56/interactions

そこで、ネストされたルートを次のように追加しました。

Social.Router.map(function() {
    this.resource('accounts',  { path: '/accounts' }, function(){
        this.resource('account', { path: ':account_id'}, function(){
            this.route('interactions', { path: '/interactions'});
        });
    });

});

しかし、そのルートにアクセスすると、次のエラーが発生します。

Uncaught Error: assertion failed: The route interactions was not found core.libs.js:2236
Uncaught Error: You cannot modify child views while in the inBuffer state core.libs.js:19298

したがって、空の InteractionsRoute も追加しましたが、解決しませんでした:

Social.InteractionsRoute = Ember.Route.extend();

何がうまくいかないのかについて誰かが意見を持っていますか?

さらに、次のようなインターフェイスにボタンを追加しようとしています。

{{#linkTo "interactions"}}@ Interactions{{/linkTo}}
4

2 に答える 2

2
Social.Router.map(function() {
    this.resource('accounts',  { path: '/accounts' }, function(){
        this.resource('account', { path: ':account_id'}, function(){
            this.route('interactions', { path: '/interactions'});
        });
    });

});

このように、インタラクションへの URL は #/interactions です

#/accounts/56/interactions したがって、インタラクションのパス フックの前にあるスラッシュを削除する必要があります。削除しないと、このルートがルートからアクセスされることを示します。

Social.Router.map(function() {
    this.resource('accounts',  { path: '/accounts' }, function(){
        this.resource('account', { path: ':account_id'}, function(){
            this.route('interactions', { path: 'interactions'});
        });
    });

});

ちなみに、パス フックを宣言しない場合、URL はルート名と同じになります。したがって、これを使用することもできます:

Social.Router.map(function() {
    this.resource('accounts', function(){
        this.resource('account', { path: ':account_id'}, function(){
            this.route('interactions');
        });
    });

});
于 2013-05-22T12:00:56.333 に答える
1

個々のレコード ビューからリストを分割してみてください。

Social.Router.map(function() {
  this.resource('accounts');
  this.resource('account', { path: '/accounts/:account_id' }, function() {
    this.route('interactions');
  });
});

インタラクションのルート名は次のようになります。

Social.AccountInteractionsRoute = Ember.Route.extend();

http://emberjs.com/guides/routing/defining-your-routes/の表から

他のすべてが失敗した場合は、ネストされたリソースを回避して、各ルートのパスを定義することができます。

Social.Router.map(function() {
  this.resource('accounts');
  this.resource('account', { path: '/accounts/:account_id' });
  this.resource('account-interactions', { path: '/accounts/:account_id/interactions' });
});
于 2013-05-21T21:08:26.530 に答える