Emberjs TODO列表。无法创建新的'todo'

时间:2013-12-12 20:30:57

标签: ember.js controller assertions

我正在尝试使用名为“newpermitcategory”的不同名称重新制作待办事项列表。我的代码似乎与emberjs网站上的示例匹配,但是当我尝试创建一个新的permittype(todo)时,我仍然收到此错误。

Uncaught TypeError: Cannot call method 'trim' of undefined 

**我故意将newpermitcategory的复数拼写为newpermitcategorys。

这是代码

<h2>New Permit Category</h2> 
  {{input type="text" id="newpermitcategory" placeholder="Create a category and press enter" value=newPermittype action="createPermitcategory"}}
<tr id="newpermitcategory">
{{#each}}
  <td>
    <input type="checkbox" class="toggle">
    <label>{{permittype}}</label> lol
  </td>
{{/each}}
</tr>

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

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

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

      newpermitcategory.save();
    }
  }
});

VpcYeoman.Newpermitcategory = DS.Model.extend({
    permittype: DS.attr('string'),
    isCompleted: DS.attr('boolean')
});

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


VpcYeoman.Router.map(function () {
  this.resource('newpermitcategorys', { path: '/newpermitcategorys' });
  this.resource('newpermitcategory', { path: '/newpermitcategory/:newpermitcategory_id' });
});

VpcYeoman.NewpermitcategoryView = Ember.View.extend({
    templateName: 'newpermitcategory'
});

VpcYeoman.NewpermitcategorysView = Ember.View.extend({
    templateName: 'newpermitcategorys'
});


VpcYeoman.NewpermitcategorysRoute = Ember.Route.extend({
  model: function() {
    return this.store.find('newpermitcategory');
  }
});

VpcYeoman.Newpermitcategoryroute = Ember.Route.extend({

});
编辑:我最初犯了很多大写错误。命名约定在Emberjs中非常重要

1 个答案:

答案 0 :(得分:1)

您的路线和控制器名称不正确

NewpermitcategorysController

NewpermitcategorysRoute

NewpermitcategoryView

且您的操作名称不匹配

createPermitcategory和createPermitCategory

并且字段newPermittype不存在,您将输入值设置为常量"newPermittype"而不是字段newPermittype

http://emberjs.jsbin.com/OxIDiVU/15/edit