コントローラーにプロパティがあります。コンポーネントを使用して、そのコントローラー プロパティを更新したいと考えています。ガイドが言うようにテキストフィールドを使用している場合、通常のコンポーネントパラメーターの受け渡しは機能しますが、私の場合、入力フィールドではなくコードで値を変更しています。バインディングが壊れているようです。
これを行うには、propertyDidChange() または notifyPropertyChange() に似たどのメソッドを使用すればよいですか? そのメソッドを呼び出す場所がわかるように、簡単な例も提供できますか?
パーソナリティコントローラー
`import Ember from 'ember'`
PersonalitiesController = Ember.ArrayController.extend
eiValue: ->
if params.name
params.name.charAt(0)
else
'e'
nsValue: ->
if params.name
params.name.charAt(1)
else
'n'
tfValue: ->
if params.name
params.name.charAt(2)
else
't'
pjValue: ->
if params.name
params.name.charAt(3)
else
'p'
type: (->
this.get('eiValue') + this.get('nsValue') + this.get('tfValue') + this.get('pjValue')
).property('eiValue', 'nsValue', 'tfValue', 'pjValue')
typeChanged: ((model, type)->
Ember.run.once(this, 'routeToPersonality')
).observes('type')
routeToPersonality: ->
this.get('controller').transitionToRoute('personality', this.get('type'))
`export default PersonalitiesController`
パーソナリティ テンプレート
%dichotomy-selector type=type
成分
`import Ember from 'ember'`
DichotomySelectorComponent = Ember.Component.extend
eiValue: 'e'
nsValue: 'n'
tfValue: 't'
pjValue: 'p'
type: (->
newValue = this.get('eiValue') + this.get('nsValue') + this.get('tfValue') + this.get('pjValue')
this.set('controller.type', newValue)
).property('eiValue', 'nsValue', 'tfValue', 'pjValue')
actions:
toggleEI: ->
eiValue = this.get('eiValue')
if eiValue == 'e'
this.set('eiValue', 'i')
else if eiValue == 'i'
this.set('eiValue', 'e')
toggleNS: ->
nsValue = this.get('nsValue')
if nsValue == 'n'
this.set('nsValue', 's')
else if nsValue == 's'
this.set('nsValue', 'n')
toggleTF: ->
tfValue = this.get('tfValue')
if tfValue == 't'
this.set('tfValue', 'f')
else if tfValue == 'f'
this.set('tfValue', 't')
togglePJ: ->
pjValue = this.get('pjValue')
if pjValue == 'p'
this.set('pjValue', 'j')
else if pjValue == 'j'
this.set('pjValue', 'p')
`export default DichotomySelectorComponent`