mercredi 24 juin 2015

Model-data keeps saving as undefined or null

This should be a pretty simple issue, but I cannot seem to understand why my data keeps being saved as null or undefined. I have tried multiple adapters, different databases, and several methods from tutorials and blog posts and all data saves as "null" or "undefined"

Background: Ember 1.13.2 Ember-data 1.13.4. I'm trying to not use controllers but understand I may have to until routable components are a thing.

So: /app/models/person.js

import DS from 'ember-data';
export default DS.Model.extend({

  firstName: DS.attr('string'),
  lastName: DS.attr('string')
});

Then I have my pod... /app/pods/person.

So /app/pods/person/route.js

import Ember from 'ember';

export default Ember.Route.extend({

model() {
  return this.store.findAll('person');
},

actions: {

  create() {
    var newPerson = this.store.createRecord('person');
    newPerson.save();

}  }  });

And /app/pods/person/template.hbs

{{input value=model.firstName}}
{{input value=model.lastName}}

<button {{action "create"}}> Create </button>

So the data goes into the input, and if I do a {{model.firstName}} I see it binding right on the screen. It's just that when I click on "create" to try to save it, ember-data saves both fields as "null" or "undefined". Any idea why?




Aucun commentaire:

Enregistrer un commentaire