mardi 2 mai 2017

How to write query in emberjs to fetch records from config.js file based on certain condition

I am working on ember.js project, in config.js i have a list of car manufacturers, and cars.

This is a list of car manufacturers.

let manufactures = [
{
  type: 'manufacture',
  id: 'bmw',
  attributes: {
    title: 'BMW',
    owner: 'BMW',
    image: 'http://ift.tt/2oWb3PY',
    description: 'Lorem ipsum is simply a dummy text'
  }
},{
  type: 'manufacture',
  id: 'jaguar',
  attributes: {
    title: 'Jaguar',
    owner: 'Jaguar',
    image: 'http://ift.tt/2p7niVW',
    description: 'Lorem ipsum is simply a dummy text'
  }
},{
  type: 'manufacture',
  id: 'audi',
  attributes: {
    title: 'Audi',
    owner: 'Audi',
    image: 'http://ift.tt/2oWdgLv',
    description: 'Lorem ipsum is simply a dummy text'
  }
},{
  type: 'manufacture',
  id: 'honda',
  attributes: {
    title: 'Honda',
    owner: 'Honda',
    image: 'http://ift.tt/2p7bBP1',
    description: 'Lorem ipsum is simply a dummy text'
  }
}
]

This is a list of cars.

let cars = [
{
  type: 'car',
  id: 'bmw-i8',
  brand:'bmw',
  attributes: {
    title: 'BMW i8',
    manufacturer: 'BMW',
    configuration: 'Demo Cinfig one',
    color: 'red',
    image: 'http://ift.tt/2oWb3PY',
    description: 'Lorem ipsum is simply a dummy text, lorem ipsum is simply a dummy text, lreom ipsum is simply a dummy text'
  }
},
{
  type: 'car',
  id: 'audi-q7',
  brand:'audi',
  attributes: {
    title: 'Audi Q7',
    manufacturer: 'Audi',
    configuration: 'Demo Cinfig two',
    color: 'black',
    image: 'http://ift.tt/2oWdgLv',
    description: 'Lorem ipsum is simply a dummy text, lreom ipsum is simply a dummy text'
  }
},
{
  type: 'car',
  id: 'amaze',
  brand:'honda',
  attributes: {
    title: 'Amaze',
    manufacturer: 'Honda',
    configuration: 'Demo Cinfig three',
    color: 'white',
    image: 'http://ift.tt/2p7bBP1',
    description: 'Lorem ipsum is simply a dummy text, lreom ipsum is simply a dummy text'
  }
},
{
  type: 'car',
  id: 'bmw-3-series',
  brand:'bmw',
  attributes: {
    title: 'BMW 3 Series',
    manufacturer: 'BMW',
    configuration: 'Demo Cinfig four',
    color: 'black',
    image: 'http://ift.tt/2oWb3PY',
    description: 'Lorem ipsum is simply a dummy text, lreom ipsum is simply a dummy text'
  }
},
{
  type: 'car',
  id: 'bmw-z4',
  brand:'bmw',
  attributes: {
    title: 'BMW Z4',
    manufacturer: 'BMW',
    configuration: 'Demo Cinfig five',
    color: 'grey',
    image: 'http://ift.tt/2oWb3PY',
    description: 'Lorem ipsum is simply a dummy text, lreom ipsum is simply a dummy text'
  }
}
];

If i run localhost:4200/manufactures, it returns me list of all manufacturers and if i run localhost:4200/cars, it returns listing of all the cars, now i want if i run localhost:4200/manufactures/bmw, it should return me all the cars manufactured by bmw, means cars with brand bmw.

For fetching manufacturers and cars i have used this code respectively.

this.get('/manufactures', function(db, request) {
    return { data: manufactures };
});

this.get('/cars', function(db, request) {
    return { data: cars };
});

Now how to write query for localhost:4200/manufactures/bmw.




Aucun commentaire:

Enregistrer un commentaire