use*_*877 5 ember.js ember-data
我正在使用Ember v1.0.0和Ember-Data v1.0.0-beta.3构建一个简单的Ember应用程序.我有一个名为'Categoria'的模型
categoria.coffee:
App.Categoria = DS.Model.extend
nombre: DS.attr 'string'
simplified: DS.attr 'boolean'
candidatos: DS.hasMany 'candidato'
Run Code Online (Sandbox Code Playgroud)
当我尝试通过它的id找到'Categoria'时,我总是收到错误消息: 断言失败:没有找到'categorium'的模型
categoria_route.coffee:
App.CategoriaRoute = Em.Route.extend(
model: (params)->
@store.find('categoria', params.categoria_id)
)
App.CategoriaIndexRoute = Em.Route.extend(
model: ->
categoria = @modelFor('categoria')
categoria.reload() if categoria.get('simplified')
categoria
)
Run Code Online (Sandbox Code Playgroud)
由于西班牙语命名的模型,我已经指定了变形规则.
store.coffee:
Ember.Inflector.inflector.irregular('categoria', 'categorias')
Ember.Inflector.inflector.rules.irregularInverse['categorias'] = 'categoria'
App.ApplicationAdapter = DS.ActiveModelAdapter()
App.ApplicationSerializer = DS.ActiveModelSerializer.extend()
Run Code Online (Sandbox Code Playgroud)
我想知道商店的find方法是否使用了一组不同的变形规则?还是有其他地方我应该宣布这个模型的变形规则?
值得一提的是,对该模型的服务器请求是正确的(到正确的URL)并且它们的响应很好.
我试图使用Ember Guides#Method Find(http://emberjs.com/api/data/classes/DS.Store.html#method_find)中store.find提到的方法使用不同的语法,但错误是相同的.
问题是当它试图将json响应单一化时,它试图单一化categoria并返回categorium,你的复数运作正常.
var iff = Ember.Inflector.inflector;
iff.irregular('categoria', 'categorias');
// this adds a test for when it finds categoria and you are trying to singularize, return categoria
iff.singular(/categoria/, 'categoria');
Run Code Online (Sandbox Code Playgroud)
http://emberjs.jsbin.com/ICeGuzuX/3/edit
| 归档时间: |
|
| 查看次数: |
718 次 |
| 最近记录: |