dimanche 7 juin 2015

TypeError: Cannot read property 'hasOwnProperty' of undefined

I am prototyping an emberjs app. I am facing a problem when I try to save the data.

My model:

App.User = DS.Model.extend({
id          : DS.attr('string'),
name        : DS.attr('string'),
description : DS.attr('string')

});

My Controller:

App.UsersAddController = Ember.ArrayController.extend({
actions : {
    addUser : function(){
        var name = this.get('name');
        var description = this.get('description');

        if (!name.trim()&&!description.trim()){return;}

        var user = this.store.createRecord('user', {
            'id'            : 'id-' + Math.random().toString(36).substr(2, 16),
            'name'          : name,
            'description'   : description
        });

        this.set('id', '');
        this.set('name', '');
        this.set('description', '');

        user.save();
    }
}

});

My template:

{{input type="text" placeholder="Name" value=name class="name-input"}}
            {{input type="text" placeholder="Description" value=description class="name-input"}}
            <button {{action 'addUser'}} class="submit">Submit</button>

The event bubbles up to the right controller. But fails to save. I am a beginner with emberjs. Please help me out.

Aucun commentaire:

Enregistrer un commentaire