无法使用ember-data模型添加数据

时间:2017-01-06 11:34:43

标签: ember.js ember.js-view

控制器/新客户

  actions: {
    addInfo: function() {
      var name = this.get('name');
      var e_mail = this.get('e-address');
      var emoney = this.get('e-money');
      var newCustomer = this.store.createRecord('customers', {
        name    : name,
        email   : e_mail,
        emoney  : emoney
      });
      newCustomer.save();
      alert("You\'re added");
    }

型号/ customers.js

import DS from 'ember-data';

export default DS.Model.extend({
    name:DS.attr('string'),
    email:DS.attr('string'),
    emoney:DS.attr('number'),
    rev: attr('string')
});

模板/新customer.hbs

<form class="form-horizontal">
    <div class="form-group control-group error">
        <label class="control-label" for="inputError">Name</label>
        {{input type="text" class="form-control" value=name placeholder = "Enter your name" size="15"}}
    </div>
    <div class="form-group">
        <label>Email Address</label>
        {{textarea type="text" class="form-control" value=e-address placeholder = "Enter your Email Address"}}
    </div>
    <div class="form-group">
        <label>E-Money</label>
        {{input type="number" class="form-control" value=e-money}}
    </div>
    <button {{action 'addInfo'}}type="button" class="btn btn-primary">Submit !!</button>
</form>

我错过了什么吗?单击提交按钮时出现在控制台上的错误是:

无法加载资源:服务器响应状态为404(未找到) vendor.js:27458 Ember数据请求POST /客户返回404 有效载荷(text / html; charset = utf-8) 无法POST /客户

错误     在AdapterError(http://localhost:4200/assets/vendor.js:83957:16)     在Class.handleResponse(http://localhost:4200/assets/vendor.js:85238:14)     at ajaxError(http://localhost:4200/assets/vendor.js:85736:25)     在Class.hash.error(http://localhost:4200/assets/vendor.js:85310:23)     在火上(http://localhost:4200/assets/vendor.js:3637:31)     at Object.fireWith [as rejectWith](http://localhost:4200/assets/vendor.js:3767:7)     完成后(http://localhost:4200/assets/vendor.js:9576:14)     在XMLHttpRequest。 (http://localhost:4200/assets/vendor.js:9816:9) defaultDispatch @ vendor.js:27458

1 个答案:

答案 0 :(得分:0)

Ember数据显示正常,但您的API服务器未正常运行或配置。

Normal color Now I am Red Now I am Green and back to Red 尝试将记录保存到您的API,错误正在解释确切的问题:

newCustomer.save();

在您的API上尝试Failed to load resource: the server responded with a status of 404 (Not Found) vendor.js:27458 Ember Data Request POST /customers returned a 404 Payload (text/html; charset=utf-8) Cannot POST /customers 数据POST导致服务器上的数据为404。

相关问题