小编Ber*_*nni的帖子

用于显示/编辑和创建的相同Ember.JS模板

我正在使用Ember.JS编写一个CRUD应用程序:

  • 显示"操作"列表;
  • 用户可以单击一个操作来显示它,或单击按钮以创建新操作.

我想使用相同的模板来显示/编辑现有的模型对象并创建一个新的模型对象.

这是我使用的路由器代码.

App = Ember.Application.create();

App.Router.map(function() {
    this.resource('actions', {path: "/actions"}, function() {
        this.resource('action', {path: '/:action_id'});
        this.route('new', {path: "/new"});
    });
});

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

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

App.ActionRoute = Ember.Route.extend({
    events: {
        submitSave: function () {
            this.get("store").commit();
        }
    }
});

App.ActionsNewRoute = Ember.Route.extend({
    renderTemplate: function () {
        this.render('action');
    },

    model: function() {
        var action = this.get('store').createRecord(App.Action);       
        return action;
     },

    events: {
        submitSave: function () …
Run Code Online (Sandbox Code Playgroud)

ember.js ember-router

4
推荐指数
1
解决办法
653
查看次数

标签 统计

ember-router ×1

ember.js ×1