我的表单有主体和主题输入以及标签输入,因此用户可以输入任意数量的标签(保存到tagList),然后提交请求。问题:JSON.stringify(z)做这样的事情将对象添加到hasMany错误
新请求:{“subject”:“this is subject”,“body”:“this is body”,“tags”:[“fixture-0”的“夹具-1”]}
不但得不到标签要我输入的文字,我得到夹具-0 ...
import Ember from "ember";
export default Ember.ArrayController.extend({
tagList: [],
actions: {
addRequest: function() {
var z = this.store.createRecord("Request", {body: this.get("body"), subject: this.get("subject")
});
this.get("tagList").forEach(function(entry){
console.log("adding tag to request: "+entry.get("tagt"));
z.get("tags").pushObject(entry);
});
console.log("New request:" + JSON.stringify(z));
z.save();
},
addTag: function(){
console.log("adding " + this.get("tag"))
var t = this.store.createRecord("tag", {tagt: this.get("tag")});
this.get("tagList").pushObject(t)
}
}
});