So I need to do so that clicking on the store would stop the page with the goods of this store. When passing the store's id through the link URL changes but in the product's route model(params) the params is empty
import DS from 'ember-data';
export default DS.Model.extend({
name: DS.attr('string'),
address: DS.attr('string'),
phone: DS.attr('string'),
shops: DS.belongsTo('shop'),
});
import DS from 'ember-data';
export default DS.Model.extend({
name: DS.attr('string'),
address: DS.attr('string'),
phone: DS.attr('string'),
products: DS.hasMany('product'),
});
import EmberRouter from '@ember/routing/router';
import config from './config/environment';
const Router = EmberRouter.extend({
location: config.locationType,
rootURL: config.rootURL
});
Router.map(function() {
this.route('shops', function() {
this.route('new');
this.route('edit', { path: '/:shop_id/edit' });
});
this.route('products',{ path: '/products/:shop_id' }, function() {
this.route('new');
this.route('edit',{ path: '/:product_id/edit' });
});
});
export default Router;
import Route from '@ember/routing/route';
export default Route.extend({
model(params) {
console.log(params); // this show {}
return this.store.findRecord('product', params.shop_id);
},
actions: {
deleteProduct(product) {
let confirmation = confirm('Are you sure?');
if (confirmation) {
product.destroyRecord();
}
}
}
})
<h2>List</h2>
<div class="row">
<div class="col-md-4">
<div class="panel panel-default library-item">
<div class="panel-heading">
<h3 class="panel-title"></h3>
</div>
<div class="panel-body">
<p>Address: </p>
<p>Phone: </p>
<p>Phone: </p>
</div>
</div>
<div class="panel-footer text-right">
Edit
<button class="btn btn-danger btn-xs" >Delete</button>
</div>
</div>
<h1> </h1>
</div>
Now I need to associate the store with the product, record and click on the link to find the goods of this store
Aucun commentaire:
Enregistrer un commentaire