Điều này có thể được thực hiện với Aurelia custom attributes tính năng.
Tạo một file javascript mới để mô tả các thuộc tính (tôi gọi là thuộc tính "animateonchange"):
import {inject, customAttribute} from 'aurelia-framework';
import {CssAnimator} from 'aurelia-animator-css';
@customAttribute('animateonchange')
@inject(Element, CssAnimator)
export class AnimateOnChangeCustomAttribute {
constructor(element, animator) {
this.element = element;
this.animator = animator;
this.initialValueSet = false;
}
valueChanged(newValue){
if (this.initialValueSet) {
this.animator.addClass(this.element, 'background-animation').then(() => {
this.animator.removeClass(this.element, 'background-animation');
});
}
this.initialValueSet = true;
}
}
Nó nhận các yếu tố và CSS làm phim hoạt hình trong constructor. Khi giá trị thay đổi, nó sẽ sinh động phần tử với tên lớp CSS được xác định trước. Thay đổi đầu tiên bị bỏ qua (không cần phải hoạt ảnh khi tải ban đầu). Dưới đây là làm thế nào để sử dụng yếu tố tùy chỉnh này:
<template>
<require from="./animateonchange"></require>
<div animateonchange.bind="someProperty">${someProperty}</div>
</template>
Xem ví dụ hoàn chỉnh in my blog hoặc on plunkr
Làm thế nào để thay đổi dữ liệu? Những thay đổi là gì? – dfsq
@dfsq Xem mô hình nhận được từ websocket và cập nhật một mục trong trường "mục". Sự ràng buộc của Aurelia sau đó cập nhật DOM. – Mikhail
Bạn cần sử dụng mô-đun aurelia-animator-css. Tôi sẽ tạo một ví dụ sau nếu bạn không tự mình tìm ra. – dfsq