【问题标题】:Ember.js - Cannot render the 'edit' .hbs for an instance of a model.Ember.js - 无法呈现模型实例的“编辑”.hbs。
【发布时间】:2014-02-07 21:25:48
【问题描述】:

我正在尝试 {{#link-to}} 模型特定实例的“/edit”路线,“category/2”将路线设为“category/2/edit”。

问题是当我使用 url 'category/2/edit' 时,页面仍保留在 'category/2' 页面上,除了模型中为 'category' 定义的所有属性例如 {{CategoryType}} 会消失。

执行此操作时我没有收到任何错误。

事不宜迟,这是我的代码。

router.js ----

  this.resource('category', { path: '/category/:category_id' }, function() {
    this.route('edit');
  });

category.hbs ----

注意:{{CategoryName}} 最初会在页面首次加载时显示。只有当页面重新加载或我尝试链接到“编辑”时它才会消失。

Category: {{ProjectName}}
{{#link-to 'this.edit'}}<button>Edit this</button>{{/link-to}}

category_route.js ----

注意:*我在模型中定义 :category_id*

    VpcYeoman.CategoryRoute = Ember.Route.extend({   
        model: function(params) {       
            return {
                id: params.category_id
             };
        }
    });

category_model.js ----

注意:我把其他的灯具都删掉了

VpcYeoman.Category = DS.Model.extend({
    CategoryName: DS.attr('string'),
    workflow: DS.belongsTo('category', {
        polymorphic: true
    }),
    classNameBindings: ['isAdministrator']
});

VpcYeoman.Category.FIXTURES=[
    {
      id: 2,
      RecordCategoryID: 2,
      Name: "Nilport",
      CategoryName: "Broden Cannon Project"
    }
];

我很欣赏这些家伙!

【问题讨论】:

  • {{link-to "this.edit"}}改成{{link-to "edit"}}或者{{link-to "category.edit" this}}能用吗?
  • 它们都不起作用,因为直接输入 url 'localhost:9000/#/category/2/edit' 不会改变页面。

标签: ember.js model routes edit handlebars.js


【解决方案1】:

在 category.hbs 中包含 {{outlet}}

您可能还需要为编辑路线设置模型:

VpcYeoman.CategoryEditRoute = Ember.Route.extend({   
    model: function(params) {       
        return {
            id: params.category_id
         };
    }
});

【讨论】:

    猜你喜欢
    • 2012-12-26
    • 2020-04-13
    • 1970-01-01
    • 2015-01-04
    • 2021-05-20
    • 1970-01-01
    • 1970-01-01
    • 2013-11-04
    • 1970-01-01
    相关资源
    最近更新 更多