Where is the device data in ember.js with cli

I am trying to use the binding data in an ember application created with cli. I can not find my data. The inspector shows that I have a model called post, but nothing in it. I am not sure why it does not work, so I am sending files that, in my opinion, are relevant ...

models / post.js

var Post = DS.Model.extend({ title: DS.attr('string'), content: DS.attr('string'), publishDate: DS.attr('date') }); Post.reopenClass({ FIXTURES: [ { id: 1, title: "Writing a blog in Ember", content: "I am writting a blog", publishDate: "05/22/2104" }, { id: 2, title: "Writing a blog in Ember", content: "I am writting a blog", publishDate: "05/22/2104" } ] }); export default Post; 

router.js

 var Router = Ember.Router.extend({ location: ENV.locationType }); Router.map(function() { this.resource('posts', { path: '/' }); }); export default Router; 

routes / index.js

 export default Ember.Route.extend({ model: function() { return this.store.find('post'); } }); 

Controllers / posts.js

 var PostsController = Ember.ArrayController.extend({ }); export default PostsController; 

Templates / posts.hbs

 <p>Test</p> <ul> {{#each}} <li> {{title}} </li> {{/each}} </ul> 

I think this problem is specific to ember-cli. I have tools that work with the Ember App Kit, but you want to work with ember-cli. I added an adapter and tried to change the way the fixtures are mounted:

adapters / post.js

 var PostAdapter = DS.FixtureAdapter.extend({}); export default PostAdapter; 

Modified models /post.js

 var Post = DS.Model.extend({ title: DS.attr('string'), content: DS.attr('string'), publishDate: DS.attr('date') }); Post.FIXTURES = [ { id: 1, title: "Writing a blog in Ember", content: "I am writting a blog", publishDate: "05/22/2104" }, { id: 2, title: "Writing a blog in Ember", content: "I am writting a blog", publishDate: "05/22/2104" } ]; export default Post; 

This still does not work. The Ember inspector shows messages with the correct fields (id, title, content publishDate), but not the actual data.

+7
javascript
source share
4 answers

I needed to add an adapter adapter to:

adapters / application.js

 export default DS.FixtureAdapter.extend({}); 

And then he worked with the reopenClass version:

models / post.js

 var Post = DS.Model.extend({ title: DS.attr('string'), content: DS.attr('string'), publishDate: DS.attr('date') }); Post.reopenClass({ FIXTURES: [ { id: 1, title: "Writing a blog in Ember", content: "I am writting a blog", publishDate: "05/22/2104" }, { id: 2, title: "Writing a blog in Ember", content: "I am writting a blog", publishDate: "05/22/2104" } ] }); export default Post; 
+19
source share

In addition to the aforementioned call to the reopenClass method, you also need to add import to your Brocfile.js for EmberData p>

You can do it like this:

 app.import({ development: 'vendor/ember-data/ember-data.js', production: 'vendor/ember-data/ember-data.prod.js' }, { 'ember-data': [ 'default' ] }); 

Thanks to this, I pleasantly put a message to help me understand this: http://www.blakeerickson.com/posts/2014/06/17/ember_cli_todomvc_tutorial

+2
source share

The accepted answer is correct, but you can generate files using ember-cli:

 ember g adapter application 

It generates:

 installing adapter create app/adapters/application.js installing adapter-test create tests/unit/adapters/application-test.js 
0
source share

You need to define devices as:

 Post.FIXTURES = [ { id: 1, title: "Writing a blog in Ember", content: "I am writting a blog", publishDate: "05/22/2104" }, { id: 2, title: "Writing a blog in Ember", content: "I am writting a blog", publishDate: "05/22/2104" } ]; 

And you should also configure ApplicationAdapter:

 App.ApplicationAdapter = DS.FixtureAdapter; 

Here is an example http://emberjs.jsbin.com/yutas/1/edit and a reference section .

-one
source share

All Articles