0

我尝试在 Ember.js 中使用路由,但它似乎无法正常工作。

完整的代码在 Github 上,但一部分如下:

define(['ember', 'app/controllers/controller', 'app/views/view'], function (ember, controller, view) {
    var Router = Ember.Router.extend({
        root: Ember.State.extend({
            index: Ember.State.extend({
                // location: Ember.Location.create({style: 'hash'}),
                location: 'hash',
                enableLogging: true,
                route: '/',
                redirectsTo: 'news.index'
            }),
            news: Ember.State.extend({
                route: '/news',
                // showPost : Ember.State.transitionTo('post'),
                test: Ember.ViewState.extend({
                    route: '/test',
                    view: view.appendTo('body')
                }),
                index: Ember.ViewState.extend({
                    route: '/',
                    view: null
                })
            })
        })
    });
    var router = Router.create({});
    return router;
});
4

1 回答 1

4

我认为您需要将代码更改为:

define(['ember', 'app/controllers/controller', 'app/views/view'], function (ember, controller, view) {
    var Router = Ember.Router.extend({
        // These are properties of Ember.Router and should be defined here
        location: 'hash',
        enableLogging: true,

        root: Ember.State.extend({
            index: Ember.State.extend({
                route: '/',
                redirectsTo: 'news.index'
            }),
            news: Ember.State.extend({
                route: '/news',
                // showPost : Ember.State.transitionTo('post'),
                test: Ember.ViewState.extend({
                    route: '/test',
                    view: view.appendTo('body')
                }),
                index: Ember.ViewState.extend({
                    route: '/',
                    view: null
                })
            })
        })
    });
    var router = Router.create({});
    return router;
});

让我知道这是否有效。

更新

实际上你也不应该使用 ViewState 。它正在贬值。按照指南http://emberjs.com/guides/outlets/

于 2012-06-21T04:02:30.837 回答