我对Ember.js比较陌生,我试图研究如何使用ember工作,并且我遇到了这个问题:从Ember.js路由中,我将调用我的django api,如下所示: this.store.findAll('MYMODEL', 'ANOTHER_MODEL_ID')
这个findAll会产生一个像/ mymodel / another_model_id /这样的api调用,其中another_model_id是一个动态id(类似字符串的uuid)。
我试图使用扩展ApplicationAdapter的自定义适配器(mymodel适配器)覆盖findAll方法(JSONAPIAdapter带有自定义buildUrl以添加尾部斜杠)。 但我的尝试失败了,因为在findAll重写的方法中,我无法访问ANOTHER_MODEL_ID参数。 我也试图用相同的结果覆盖urlForFindAll和buildUrl方法。
做这种事情的最佳方法是什么?我该怎么办?
I'm relatively new to Ember.js and I'm trying to studing how ember works and I've this problem: from an Ember.js route I will call my django api like this: this.store.findAll('MYMODEL', 'ANOTHER_MODEL_ID')
This findAll will produce an api call like /mymodel/another_model_id/ where another_model_id is a dynamic id (uuid like string).
I've tried to override the findAll method with a custom adapter (mymodel adapter) that extends the ApplicationAdapter (JSONAPIAdapter with a custom buildUrl for adding trailing slash). But my attempt failed, because in findAll overridden method I can't reach the ANOTHER_MODEL_ID parameter. I've also tried to override urlForFindAll and buildUrl methods with the same results.
What is the best method for doing this kind of things and how can I do?
最满意答案
findAll没有id参数。 你是说find('modelname','id')?
import DS from 'ember-data'; export default DS.Adapter.extend({ findAll: function(store, type, sinceToken) { var query = { since: sinceToken }; return new Ember.RSVP.Promise(function(resolve, reject) { Ember.$.getJSON(`/${type.modelName}`, query).then(function(data) { resolve(data); }, function(jqXHR) { reject(jqXHR); }); }); } });I've resolved using urlForQuery function and declaring my adapter as JSONAPIAdapter extending it with DataAdapterMixin.
更多推荐
发布评论