Ember资源URL:如何使用其他值而不是ID?

时间:2012-03-07 05:59:43

标签: ember.js

我需要使用Ember资源使用其架构中的一个值发送其查询。

假设我已经定义了这个资源:

App.SomeModule = Ember.Resource.define(
{
    url: './api/some',
    schema:
    {
        id: Number,
        fodder: Number,
        whatever: Number,
        units:
        {
            type: Ember.ResourceCollection,
            itemType: 'App.OtherModule',
            url: './api/other/%@'
        }
    }
});

当此资源需要加载其“单位”时,它会自动使用网址“api / other /(id)”发送查询。但是我需要使用其他值,例如(fodder)或(等等) ,不是id。我认为(%@)需要更换,但是如何?

1 个答案:

答案 0 :(得分:2)

您可能希望将url定义为函数:

units: {
  url: function() {
    // your custom code here:
    return '/api/other/%@'.fmt(this.get('fodder'));
  }
}
相关问题