当保存一定的实体我想,如果发送电子邮件通知Approved
该实体的属性发生变化。
if (changedEntity.Entity is Option)
{
// Pseudo
if changedEntity.Entity.Approved changed {
send notification()
}
}
是否有某种方式来做到这一点? 或者,可以将它通过比较来完成CurrentValues
对OriginalValues
?
如果你知道你要“看”的具体的实体,您可以使用EntityAspect.propertyChanged事件(见: http://breeze.github.io/doc-js/api-docs/classes/EntityAspect.html#event_propertyChanged ) 像这样:
// assume order is an order entity attached to an EntityManager.
myEntity.entityAspect.propertyChanged.subscribe(function(propertyChangedArgs) {
// this code will be executed anytime a property value changes on the 'myEntity' entity.
if ( propertyChangedArgs.propertyName === "Approved") {
// perform your logic here.
}
});
或者,如果你想观看每一个实体的特定属性,你就可以使用EntityManger.entityChanged事件类似的测试(参见: http://breeze.github.io/doc-js/api-docs/classes/EntityManager。 HTML#event_entityChanged )
myEntityManager.entityChanged.subscribe(function (args) {
// entity will be the entity that was just changed;
var entity = args.entity;
// entityAction will be the type of change that occured.
var entityAction = args.entityAction;
if (entityAction == breeze.EntityAction.PropertyChange) {
var propChangArgs = args.args;
if (propChangeArgs.propertyName === "Approved") {
// perform your logic here
}
}
});
更多细节可以在这里找到: http://breeze.github.io/doc-js/lap-changetracking.html
使用myEntity.entityAspect.originalValues
。 该散列将只对更改的属性值。