2013-03-05 15 views
0

有什么方法可以使用find方法来请求这样的URL?Ember数据 - 按ID查找并使用过滤器

http://awesomedomain.com/api/models/1/?foo=bar

现在,如果我用Model.find({id: 1, foo: 'bar'}),它会自动使用findQuery和请求的URL是api/models/?id=1&foo=bar,这引发了后端不同的方法。

另一种选择是在后端路由上解决这个问题,但是我想知道它是否可以在Ember内实现。

+0

这个应用程序的服务器后端是什么? rails/django? – 2013-03-05 11:45:16

+0

我正在使用Yii框架(PHP),但真正的问题是如果它可以在前端级别解决。 – 2013-03-05 11:53:46

+0

只看源代码,它会出现,因为你只得到1或其他(id查找或query_string查找)不支持开箱即用。如果问题还没有存在,那么在github网站上可能需要提出类似这样的请求 – 2013-03-05 12:38:21

回答

1

我同意,你应该能够提供的东西是这样的:现在

Your.Model.find(1,{foo:"bar"}) 

,你唯一可以做的事情是:

Your.Model.find(1) 

然后在你的RestAdapter,覆盖AJAX请求手动添加哈希/查询参数:

Your.RESTAdapter = DS.RESTAdapter.extend({ 
    url: 'http://awesomedomain.com/api/models', 
    ajax: function(url, type, hash) { 
    hash.url = url; 
    hash.type = type; 
    hash.dataType = 'json'; 
    hash.contentType = 'application/json; charset=utf-8'; 
    hash.context = this; 
    hash.data = {foo:"bar"}; 
    jQuery.ajax(hash); 
    } 
});