视图更改时,Ember.js更新模型
Ember.js update model when view changed?
这里是ember的新手,我想如果你在视图和模型之间绑定数据,那么如果其中一个发生了变化,双方都会同步。
目前,我用Emberfire设置了我的模型,它返回一系列颜色:
App.ApplicationRoute = Ember.Route.extend({
model: function() {
return EmberFire.Array.create({
ref: new Firebase("https://ember-starter.firebaseio.com/shape")
});
},
setupController: function(controller, model) {
controller.set('model', model);
}
});
我的模板设置如下:
<button {{action "add"}}>Draw</button>
{{#each controller}}
{{#view App.ShapeView contentBinding="content"}}
<div>{{color}}</div>
{{/view}}
{{/each}}
我有一个按钮可以为阵列添加新颜色:
App.ApplicationController = Ember.ArrayController.extend ({
actions: {
add: function() {
var newColor = {
color: "#222222"
};
this.pushObject(newColor);
}
}
});
在视图中,我设置了一个点击操作来设置颜色属性:
App.ShapeView = Ember.View.extend({
click: function() {
var self = this;
var changeColor = self.set('context.color', '#121212');
}
});
使用当前设置,我可以获取/显示颜色列表,并在单击时将颜色更改为#12122。然而,数据并不能持久存在于模型中(firebase)。我想知道是我做错了什么,还是有更好的方法来保存/同步视图和模型之间的更改。
提前感谢!
可能是因为您的add函数中有一个拼写错误。。。this.pushObject(newColore);应该是this.pushObject(newColor);
add: function() {
var newColor = {
color: "#222222"
};
this.pushObject(newColor);
}
祝好运
相关文章:
- D3.js更新堆叠条形图
- 将节点.js更新为 0.12 标头错误
- 使用动态 js 更新画布
- 通过JS更新时,Angularjs输入不会更改,而不是手动更新
- Riot Js更新标签
- 视图更改时,Ember.js更新模型
- sails.js更新或添加新行
- Knockout.js-更新父视图模型中的数组,在第二个视图模型中使用值
- 使用node.js更新和删除按钮
- 使用express和node.js更新mongodb中的单个记录
- 三.js:更新几何图形与替换
- exit().remove() 在 d3.js 更新之前不会删除旧图表
- 从 JS 更新角度材料输入值
- Ember js - 更新其他表后,有许多关系中断
- 时刻JS更新时区缩写
- 视频.js - 更新字幕/字幕
- JWT 从节点.js更新有效负载
- 节点.js更新文件中的 JSON 数据
- 角度.js更新模型
- D3 js 更新图只是在顶部添加新点