Emberjs显示和创建模型的子类

时间:2013-12-24 16:55:54

标签: ember.js model controller subclass each

型号:'类别' 子类:'工作流'

我正在尝试为每个“类别”显示不同的“工作流程”,但我收到此错误>>

Uncaught Error: Nothing handled the event 'createWorkflow'. 

这是一些代码

VpcYeoman.Category = DS.Model.extend({
    permittype: DS.attr('string'),
    isCompleted: DS.attr('boolean'),
    classNameBindings: ['isAdministrator']
});

VpcYeoman.Workflow = VpcYeoman.Category.extend({
    workflowtype: DS.attr('string')
})

VpcYeoman.Category.FIXTURES = [
  {
    id: 1,
    permittype:'Building'
  },
  {
    id: 2,
    permittype:'Electrical'
  },
  {
    id: 3,
    permittype:'Zoning'
  },
  {
    id: 4,
    permittype:'Fire'
  }
];

我对如何为这个子类制作FIXTURES感到有点困惑。我尝试重新创建VpcYeoman.Workflow.FIXTURES = [id& workflowType examples],但它没有显示。

Category.hbs

<div class="department-header">
  <div class="user-header">
    Category: {{permittype}}
  </div>
</div>
<table class="table table-hover table-responsive">
  <thead>
    <tr class="people-list">
      <td><h4>Workflow Type</h4></td>
    </tr>
  </thead>
    <table>
    {{#each workflows}}
      <tr>
        <td>
          {{workflowtype}}
        </td>
      </tr>
    {{/each}}
  </table>

  <div class="input-bar">
      <img src="images/lightning-icon-edited.png" class="input-icon">
      {{input type="text" value=newWorkflowtype placeholder="Create a workflow and press enter" action="createWorkflow"}}
  </div>

&安培;&安培;

VpcYeoman.CategoriesController = Ember.ArrayController.extend({
  actions: {
    createCategory: function () {
      var permittype = this.get('newPermittype');
      if (!permittype.trim()) {return;}

      var category = this.store.createRecord('category', {
        permittype: permittype
      });

      this.set('newPermittype', '');

      category.save();
    },
    createWorkflow: function () {
      var workflowtype = this.get('newWorkflowtype');
      if (!workflowtype.trim()) {return;}

      var workflow = this.store.createRecord('workflow', {
        workflowtype: workflowtype
      });

      this.set('newWorkflowtype', '');

      workflow.save();
    }
  }
});

&安培;&安培;

VpcYeoman.CategoriesRoute = Ember.Route.extend({
  model: function() {
    return this.store.find('category');
  },
  setupController:function(controller, model){
    this._super(controller, model);
    controller.set('workflows', this.store.find('workflow'));
  }
});

VpcYeoman.CategoryRoute = Ember.Route.extend({

});

1 个答案:

答案 0 :(得分:1)

我假设你有一个基于不同名称的东西的类别和类别路线/模板。

操作将转到特定路线的控制器Category,然后是路线的路线Category,然后是路线CategoriesApplication

看起来您正在Categories控制器上设置工作流程,但尝试在Category模板中使用它