emberjs属性未保存在表单提交

时间:2015-06-22 14:29:46

标签: ember.js ember-data

我在组件中有这个表单:

<form class="" {{action "saveEdit" on="submit"}}>
  {{input type="text" id="name"value=person.name  }}
  {{input type="date" id="dob" value=person.date_of_birth}}
  <button type="submit">Save</button>
</form>

提交后,用户sendAction将其发送到路线:

   saveEdit: function () {
      this.set("isEditing", false);

      this.sendAction("action", this.get("person"));
    } 

我保存的地方:

saveEdit: function (person) {
      person.save();
    }

但是,只保存名称

这不起作用:

  saveEdit: function () {
      this.set("isEditing", false);
      var dob= $("#dob").val();
      var person = this.get("person");
      person.set("date_of_birth", dob);
      this.sendAction("action", person);
    }

当我在console.log中获取person对象时:

_data: Object
date_of_birth: null
id: "1"
name: "Joey"

名称更新,但date_of_birth设置为null。

我不明白为什么会发生这种情况

1 个答案:

答案 0 :(得分:0)

这是模型定义中的内容。我将其中一个属性设置为“date”,但表单正在发回一个字符串。我只是将属性设置为“字符串”,它工作正常。