jeudi 9 avril 2015

My data shows on one page and not the other on Ember

I'm using Ember Data to build a web app, and somehow data shows on one template and not the other. My Ember console shows that the model is correctly hooked up to the route, but I don't know why the data won't show.


The data I'm trying to show is {{stackTitle}} in model 'stack'.


I'm using the local storage adapter provided via Ember's tutorial... maybe that's the problem?


Here's my template (the one that's not displaying data):



<script type="text/x-handlebars" data-template-name="stack">
<div class="container-fluid">
<div class="row">
<a href="#"><button class="btn btn-default" type="button">Back</button></a>

<button class="btn btn-default" type="submit">Save</button>
</div>

<h1>
<label {{action "editStack" on="doubleClick"}}>{{stackTitle}}</label>

{{input
value=stackTitle
action="createStack"}}

{{debugger}}
<div>{{stackTitle}}</div>

</h1>



{{partial "todos"}}

</div>
</script>


And here's my router:



Todos.StackRoute = Ember.Route.extend({
model: function(params) {
return this.store.find('stack', params.stack_id);
},
});


My controller:



Todos.StackController = Ember.Controller.extend({

setupController: function(controller, model) {
controller.set('model', model);
},

actions: {

createStack: function() {

var title = this.get('stackTitle');
if (!title.trim()) { return; }

var stack = this.store.createRecord('stack', {
stackTitle: title,
});

stack.save().then(function() {
var promises = Ember.A();
stack.get('todos').forEach(function(todo) {
promises.push(todo.save());
});
Ember.RSVP.Promise.all(promises).then(function(resolvedPromises){
alert('all saved!');
})
});

console.log(this.store.all('stack'));
},
}
});


My model:



Todos.Stack = DS.Model.extend({
stackTitle: DS.attr('string'),
todos: DS.hasMany('todo', {async: true} ),
isTaken: DS.attr('boolean'),
});


I'd love if you could point me in the right direction. Thank you!





Aucun commentaire:

Enregistrer un commentaire