[英]Ember - child component updating a property coming from query params via parent component
我正在使用Ember 1.13.0,并尝试更新来自子组件中查询参数的属性。
在子组件js中,当未定义“时间”时,我将其设置为1200。如果我在子组件中记录了“时间”的值( this.get('time') ),则在对其进行更新后,我可以看到其值正在更新。 但是它并没有通过父组件动作。
那么,如果我的价值在孩子中得到更新,为什么我不能在父母中获得价值呢?
顶级组件:
{{parent-component time = model.params.incomingTime}}
父组件:
<div>hello</hello>
{{child-component time=time}}
父组件JS:
actions: {
submit:function(){
var t = this.get('time')
}
}
子组件:
<div>Time is {{currentTime}}</div>
子组件JS:
currentTime: function(){
if(this.get('time')){
return time;
} else {
this.set('time','1200');
return '1200'
}
}.property()
顶级路线:
var route = Ember.Route.extend({
queryParams: {
time: {refreshModel:true, replace: false}
},
model: function(params){
return Ember.RSVP.hash({ params: params})
},
setupController: function(controller, model) {
controller.set('model', model);
}
})
请问incomingTime
财产进来params
如果让你的代码将工作。 否则它将失败。
{{parent-component time=model.params.incomingTime}}
UPDATE1:发送整个model.params
可能会奏效。
顶级组件:
{{parent-component modelParams=model.params}}
父组件:
<div>hello</hello>
{{child-component modelParams=modelParams}}
父组件JS:
actions: {
submit:function(){
var t = this.get('modelParams.time')
}
}
子组件:
<div>Time is {{currentTime}}</div>
子组件JS:
currentTime: function(){
if(this.get('modelParams.time')){
return time;
} else {
this.set('modelParams.time','1200');
return '1200'
}
}.property()
我通过在父组件中声明新的CP并从中返回简单的“时间”来使其工作。 现在,我将该CP传递给子级,然后通过父级中的操作对其进行更新。 这样看来可行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.