ember.js - how use model in emberJS pod structure? -


i use pods structure in ember. want create dataservice , dropdown component. way best? structure based on ember-cli.

these did before:

this pods structure: enter image description here

code in dropdown/route.js:

import ember 'ember';  export default ember.route.extend({    model: function() {      var store = this.store;      return  $.ajax({         url: 'http://.../api/category/categories', //my api url         type: 'get'        }).then(function(items) {                      items.foreach(function(item, index, enumerable) {             store.push('model',{                 id:item.id,                 name: item.title,                 value: item.id.tostring()             });          });       });      }   }); 

codes in dropdown/model.js:

import ember 'ember-data';  export default ember.model.extend({     name: ember.attr('string'),     value: ember.attr('string')    }); 

in dropdown page , have error:

error: no model found 'model'

how can solve that?

which way better? using way above or using restadapter , serializer? if second way better, please me how can that. thanks

your pods structure little bit wrong. pods structure used wrap resources in app. accordingly ember-cli docs should split directories in resource-manner, each directory can contain 3 files:

  • controller.js
  • route.js
  • template.hbs

or in case of component:

  • component.js
  • template.hbs

what can propose is:

  • move model models directory above pods (and change name, model may cause strange behaviour)
  • leave dropdown component
  • i not sure, if dataservice service instead of component, move services directory, above pods

models should define in models directory, not in pods structure. moreover, looks using ember-data (using store), create models extending ember.model. not sure if more proper approach extend ds.model instead.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -