I am new to building websites and all I want to do at this stage is to use local JSON file to retrive data instead of mirage provided in ember tutorial. you have mirage/config.js like this:
export default function() {
this.namespace = '/api';
let rentals = [{
//JSON
}];
this.get('/rentals', function(db, request) {
if(request.queryParams.area !== undefined) {
let filteredRentals = rentals.filter(function(i) {
return i.attributes.area.toLowerCase().indexOf(request.queryParams.area.toLowerCase()) !== -1;
});
return { data: filteredRentals };
} else {
return { data: rentals };
}
});
// Find and return the provided rental from our rental list above
this.get('/rentals/:id', function (db, request) {
return { data: rentals.find((rental) => request.params.id === rental.id) };
});
}
This article shows part of the solution but I don't know where it's supposed to be written. Any help would be much appreciated.
Aucun commentaire:
Enregistrer un commentaire