javascript - Emberjs template not binding to restful data -
got route data restful service
var app = ember.application.create({rootelement: '#planner'}); app.store = ds.store.extend(); app.router.map(function(){ this.resource('home'); }); app.homeroute = ember.route.extend({ model: function(){ return ember.$.getjson('/api/get-planner/'); } });
and template:
<script type="text/x-handlebars" data-template-name="home"> {{name}} </script>
somehow value of name not displayed. can confirm api returning correct json data.
ember-data expects json this:
{ planner: { name: 'test' // data } }
so if api returns json:
{ name: 'test' }
it won't work. suggest use ember-model instead (https://github.com/ebryn/ember-model), since more stable , allows customize behavior of rest adapter.
your code might this:
app.plannermodel = ember.model.extend({ name: ember.attr(), // see documentation of ember-model }); app.plannermodel.url = '/api/get-planner/'; app.plannermodel.adapter = ember.restadapter.create(); app.homeroute = ember.route.extend({ model: function() { return app.plannermodel.find(); } });
if want take approach, make sure not include ember-data , use ember-model instead.
Comments
Post a Comment