vendredi 22 avril 2016

Best practice to load external config file in Ember

I'm still quite new for Ember.js and I'm making a search box who need to load a list of types from a product-type-list.json to show some filter selects, the json is like:

data: [
    "id": "1",
    "type": "cars",
    "attributes": {
       "name": "Classical"
    },
    "id": "2",
    "type": "motos",
    "attributes": {
       "name": "Sportive"
    },
    "id": "3",
    "type": "boats",
    "attributes": {
       "name": "Sailing"
    },
    "id": "4",
    "type": "cars",
    "attributes": {
       "name": "4x4"
    },
]

and generate some select like:

<select>
   <option value="1">Classical</option>
   <option value="4">4x4</option>
</select>

<select>
   <option value="3">Sailing boat</option>
</select>

<select>
   <option value="2">Sportive moto</option>
</select>

once user select a filter, it will make a request with queryParams like: /searches?query=blue&filters[car]=4&filters[boat]=3, and get results from server, this list change rarely, so I only need to load it in once, but I'm not sure what is the best practice for this and how to implement it, should I make a service or a mixin? should I create model for it?

and I also have a question of singular/plural, because types from the json are always plural but request wait for a singular type, how can I deal this?

thanks




Aucun commentaire:

Enregistrer un commentaire