モックアップの作成に似たドラッグアンドドロップ作業領域を構築しています。私は拡大してパンすることができるより大きな、入れ子にされた要素を持つワークスペースカスタム要素を持っています。したがって、ワークスペースとすべての含まれている要素のサイズと位置データを注意深く追跡する必要があります。バインディングがAureliaで再評価された後のコールバックのトリガー
私のカスタム要素の私の添付イベントでは、私はプログラム的にビューにCSSにバインドされているJavaScriptオブジェクトとしてワークスペースの高さと幅を設定します。
workspaceCustomElement.js
は、export class WorkspaceCustomElement {
constructor(element) {
this.element = element;
}
attached() {
this.workspace.size = {
height: this.element.height * 5,
width: this.element.width * 5
}
}
}
workspaceCustomElement.html
<div css="height: ${workspace.height}px; width: ${workspace.width}px;
left: ${(element.clientWidth - workspace.width)/2}px;
top: ${(element.clientHeight - workspace.height)/2}px;"></div>
今、私の子要素の位置を取得しようとすると問題に遭遇しています。私もそれらにコールバックを添付していますが、の前にはのコールバックが添付されています。したがって、CSSバインディングは評価されておらず、サイズと位置が間違っています。
は私がattached()
が評価されたとのバインディングが更新された後にコールバックを追加する必要があります。私はsetTimeout
ハックを使ってこれを達成できますが、これはいつもうまくいくという自信がありません。
attached() {
this.workspace.size = {
height: this.element.height * 5,
width: this.element.width * 5
}
setTimeout(() => {
let components = this.element.querySelectorAll('.component');
Array.prototype.forEach.call(components, (component) => {
let model = component.model;
model.position = {
x: component.clientLeft,
y: component.clientTop
};
}
}, 0)
}
次のバインド更新後に命令をキューに入れる方が、より確実で信頼性の高い方法がありますか?
Aureliaの 'TaskQueue'はどうですか? http://stackoverflow.com/questions/36049391/is-there-a-callback-or-promise-for-aurelia-show-bind –