通过REST API提交表单

时间:2014-08-23 11:25:10

标签: ember.js

我是Ember的新手,我正在尝试通过提交表单来创建记录。这是我到目前为止编写的代码:

App.CharactersNewRoute = Ember.Route.extend({
    model: function() {
        return this.store.createRecord('character', {name: '', race: ''});
    }
});

<form {{action "createCharacter" on="submit"}}>

        <div class="form-group">    
            <label>Name</label>
            {{input value=characterName class="form-control"}}
        </div>

        <div class="form-group">    
            <label>Race</label>
            {{input id=characterRace class="form-control"}}
        </div>

        {{#link-to 'characters'}}<button class="btn btn-default">Back</button>{{/link-to}}

        <button class="btn btn-default" type="submit">Create</button>
    </form>

App.CharactersNewController = Ember.ObjectController.extend({

actions: {

    createCharacter: function() {
        var name = this.get('characterName'),
                race = this.get('characterRace');

        if (!name || !race) { return false }

        // create new character
        var character = this.store.createRecord('character', {
            name: name,
            race: race
        });

        this.set('characterName', '');
        this.set('characterRace', '');

        character.save();

    }
}
})

现在,代码停在控制器的var character = this.store.createRecord行,但控制台中没有出现错误

由于

0 个答案:

没有答案