ember.js - EmberJS not displaying results from DS.RestAdapter -
i'm new emberjs , can't seem figure out wrong code. i've read , compared different example projects hoping find "missing link" i'd appreciate second set of eyes on this:
i using:
- handlebars.js 1.0.0-rc.3
- ember-latest.js (on aws)
- ember-data-latest.js (on aws)
bleeding edge because keep getting errors whatever on website.
index.html:
<script type="text/x-handlebars" data-template-name="application"> {{outlet}} </script> <script type="text/x-handlebars" data-template-name="items"> <h2>total entries: {{length}}</h2> {{#if length}} <ul> {{#each item in controller}} <li>{{item.title}}</li> {{/each}} </ul> {{/if}} </script>
app.js:
window.app = ember.application.create({ log_transitions: true }); // model app.store = ds.store.extend({ revision: 12, adapter: ds.restadapter.extend({ bulkcommit: false, url: '/api' }) }); app.item = ds.model.extend({ id: ds.attr('number'), title: ds.attr('string') }); // router app.router.map(function () { this.resource('items', function () { this.resource('item', { path: ':item_id' }); }); }); app.indexroute = ember.route.extend({ redirect: function() { this.transitionto('items'); } }); app.applicationroute = ember.route.extend({ setupcontroller: function() { this.controllerfor('item').set('model', app.item.find()); } }); app.itemsroute = ember.route.extend({ model: function () { return app.item.find(); } }); // controller app.itemscontroller = ember.arraycontroller.extend({ sortproperties: ['title'] }); app.itemcontroller = ember.objectcontroller.extend({ isediting: false, edititem: function () { this.set('isediting', true); } });
on load, xhr request made /api/items returns follows:
{"items": [ { "id":"518c7ceeef56038b77000000", "title":"test 1" }, { "id":"518c7ceeef56038b77000001", "title":"test 2" } ] }
so data being retrieved somehow, it's not appearing user!
would appreciate pointers. thanks!
i can imagine model wrong, id
field in ember-data dosn't need specified explicitly if name id
. comment in source code reads:
get primary key name record calling serializer's
primarykey
record's type. unless overrideprimarykey
method,'id'
.
try change model simplified version:
app.item = ds.model.extend({ title: ds.attr('string') });
hope helps
Comments
Post a Comment