I’m entirely new to EmberJS. I’ve been fiddling around lately, but find my self in a bit of a jam with a specific issue. I’m still getting grips on the basic concepts of this framework, so bear with me.
Basically I want to manipulate the ember store (only locally) on page/app load. Specifically an array of queryParams should create a series of new records on page/app load.
The query could look like: http://localhost:4200/?post[]=1&post[]=2
I’m able to fetch the queryParams and loop over the desired query (here post) but as soon as i try to access the store from within the forEach loop a console error is thrown back at me: Cannot read property 'store' of undefined TypeError: Cannot read property 'store' of undefined
Here’s the index.js for the route:
import Ember from 'ember';
export default Ember.Route.extend({
beforeModel: function(transition){
console.log(transition.queryParams.post);
transition.queryParams.post.forEach(function(item){
console.log(item);
// console.log(this.store)
//
// this.store.createRecord('post', {
// title: item
// })
})
},
// manually add record using action
actions:{
addpost(){
console.log(this.store)
this.store.createRecord('post', {
title: 'a new post'
});
}
}
});
Any ideas on how to go around this? Help much appreaciated!
Here’s the whole app as a repo: https://github.com/template01/emberparamsstore
All the bests
Lasse