The app I've been putting together looks like a list of stores (with add/edit/delete options), and clicking on a store name takes you to the list of items in that store (again with add/edit/delete). The router:
Router.map(function() {
this.route('about');
this.route('stores');
this.route('shop', function() {
this.route('items', { path: '/:shop_id/items' });
this.route('edit', { path: '/:shop_id/edit' });
});
});
The model:
// app/models/shop.js
import DS from 'ember-data';
export default DS.Model.extend({
shopName: DS.attr(),
shopDetails: DS.attr(),
items: DS.hasMany('item')
});
and:
// app/models/item.js
import DS from 'ember-data';
export default DS.Model.extend({
itemName: DS.attr(),
itemDetails: DS.attr(),
itemPrice: DS.attr(),
parentShop: DS.belongsTo('shop')
});
Route for the page that displays the list of items is:
// app/routes/shop/items.js
import Ember from 'ember';
export default Ember.Route.extend({
model(params) {
return this.get('store').findRecord('shop', params.shop_id, {
include: 'items'
});
}
});
Now as far as I understand before adding an item
to a shop
I have to call peekRecord()
:
// app/controllers/shop/items.js
actions: {
saveItem() {
let currentShop = this.get('store').peekRecord('shop', /* shop id here */);
//rest of the code
}
}
from:
// app/templates/shop/items.hbs
<button type="submit" >Save</button>
The question is, how do I pass the shop id as the second argument for peekRecord()
?
Aucun commentaire:
Enregistrer un commentaire