以下のサンプルコードを参照してください。 は私がパフォーマンスを向上させるためdidReceiveAttrs
フックの代わりに、observers
経由value
性質の変化を観察したいコンポーネントmy-text-box
変更可能なセルの場合、didReceiveAttrsフックで実際のattr値を取得する方法
my-text-box.hbs
{{my-text-box value=modelName}}
を持って考えます。
my-text-box.js
didReceiveAttrs: function(args) {
if (args.oldAttrs == null) {
// This is the initial render, but I don't need to anything here.
} else if (args.newAttrs.value != args.oldAttrs.value) {
// supposed `value` was changed from outside, I can do something here...
// BUT, `args.newAttrs.value` is not always the prop value,
// `Ember` would automatically wrap it with `{{mut}}` helper.
// The data structure would be:
// {
// value: value,
// update: function (val) {
// source.setValue(val);
// }
// }
}
}
私が欲しいのは、私がATTR値がmutable
セルであるかどうかを気にする必要はありません、私はいつも本当の価値を得る方法を取得する必要があることです。 HTMLBars hook
ember-htmlbars/hooks/get-value
がありますが、公開APIには公開されていません。そして私が考えているのは、おそらくEmber
がnewAttrs
とoldAttrs
の両方に、mutable
オブジェクトの代わりに直接値を持つように変更する必要があるということです。
誰かがそれを処理する方法はありますか?ありがとう!
'newAttrs'と' oldAttrs'はパブリックAPIではありません:X – locks
'observers'を置き換えるのは難しいので、1つのプロパティが変更されているかどうかを知る必要があります。 http://emberjs.com/api/classes/Ember.Component.html#event_didReceiveAttrs – shijistar