是否可以查看修改后的实体上的特定属性是否发生了变化? [英] Is it possible to see if a specific property changed on a modified entity?
问题描述
保存某个实体时,如果该实体的批准属性已更改,我想发送通知电子邮件。
When saving a certain entity I want to send a notification email if the Approved
property of this entity has changed.
if (changedEntity.Entity is Option)
{
// Pseudo
if changedEntity.Entity.Approved changed {
send notification()
}
}
有某种方法可以做到这一点吗?还是可以将 CurrentValues
与 OriginalValues
进行比较?
Is there a certain way to do this? Or can it be done by comparing the CurrentValues
against the OriginalValues
?
推荐答案
如果知道要监视的特定实体,则可以使用 EntityAspect.propertyChanged 事件(请参阅: http://breeze.github.io/doc-js/api-docs /classes/EntityAspect.html#event_propertyChanged )像这样:
If you know the specific entity that you want to 'watch', you can use the EntityAspect.propertyChanged event (see: http://breeze.github.io/doc-js/api-docs/classes/EntityAspect.html#event_propertyChanged) like this:
// 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 )
Or if you want to watch a specific property on every entity, you can perform a similar test using the EntityManger.entityChanged event (see: 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
More detail can be found here: http://breeze.github.io/doc-js/lap-changetracking.html
这篇关于是否可以查看修改后的实体上的特定属性是否发生了变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!