保存某个实体时,如果此实体的Approved
属性发生更改,我想发送通知电子邮件。
if (changedEntity.Entity is Option)
{
// Pseudo
if changedEntity.Entity.Approved changed {
send notification()
}
}
有某种方法可以做到这一点吗?或者可以通过将CurrentValues
与OriginalValues
?
答案 0 :(得分:1)
如果您知道要查看的特定实体,可以使用 EntityAspect.propertyChanged 事件(请参阅:http://breeze.github.io/doc-js/api-docs/classes/EntityAspect.html#event_propertyChanged),如下所示:< / p>
// 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
答案 1 :(得分:0)
使用myEntity.entityAspect.originalValues
。此哈希将仅具有更改后的属性的值。