I'm wondering if there's any way for me to create a custom ember-data method so I can do things like this:
this.store.customMethod('klass')
I know I can override the existing methods for my needs but I need more control than that
Another option is to implement a custom store service.
// app/services/store.js
import DS from 'ember-data';
export default DS.Store.extend({
init: function() {
console.log('Using custom store!');
return this._super.apply(this, arguments);
}
});
Most likely what you want to do is add a custom methods to your models adapter if you want to do custom things. So in adapters/klass.js
:
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
customMethod(){
const data = {user: {email: this.get('email')}};
const baseUrl = this.urlForFindAll('user');
return Ember.$.post(`${baseUrl}/password`, data);
}
});
Then somewhere else:
const adapter = this.store.adapterFor('user');
adapter.customMethod();
But yeah sure you can extend the store. In stores/application.js
:
import DS from 'ember-data';
export default DS.Store.extend({
customMethod(model) {
// Do stuff
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.