2016-10-12 13 views
0

Ember 1.13.0を使用していて、子コンポーネントのクエリパラメータから来るプロパティを更新しようとしています。親コンポーネントを経由してクエリパラメータから来るプロパティを更新するEmber - 子コンポーネント

"time"が定義されていない場合、私は1200に設定しています。子コンポーネントに "time"(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); 
     } 
}) 
+0

私たちにルートモデルフックを見せてください? – kumkanillam

+0

フックを追加しました。 – whyAto8

答えて

0

私はそれが親コンポーネントに新しいCPを宣言し、そこから、単に「時間」を返すことで取り組んでしまいました。今私はそのCPを子供に渡して、それを親の行動で更新しています。このように動作するようです

1

ウィルincomingTimeプロパティはparamsで来ます作業。それ以外の場合は失敗します。

{{parent-component time=model.params.incomingTime}} 

アップデート1: 全体model.paramsを送信することは働くかもしれません。

最上位成分:

{{parent-component modelParams=model.params}} 

親コンポーネント:

<div>hello</hello> 
{{child-component modelParams=modelParams}} 

親コンポーネントJS:

actions: { 
submit:function(){ 
    var t = this.get('modelParams.time') 
} 
} 

子コンポーネント:

子コンポーネントJS:

currentTime: function(){ 
if(this.get('modelParams.time')){ 
    return time; 
} else { 
    this.set('modelParams.time','1200'); 
    return '1200' 
} 
}.property() 
+0

もし値があれば、私は単純に子コンポーネントでそれを返します。そうでなければ、時間を設定する必要があります。親コンポーネントでアクセスできない場合は – whyAto8

+0

'model.params.incomingTime'プロパティが' undefined'ならばember cantはchildComponentの変更をparentComponentに伝播します。ですから、 'model.params.incomingTime'のデフォルト値を持つことをお勧めします。それ以外の場合はdefaultValueロジックをモデルの内側のフックまたは対応するコントローラに移動します。 – kumkanillam

+0

それ以外の場合は、 'model.params'自体を送信して、' this.set( 'model.params.time') 'を使用してプロパティを取得し、' this.set( 'model.params'時間 '、'値 ')' – kumkanillam

関連する問題