Javascript 微风不吹';t识别修改后的实体
我有一个breeze实现,它接受一个location对象并在UI上显示属性。我对一些属性进行了更改并尝试保存更改,但breeze没有将实体识别为已更改。以下是我的代码:Javascript 微风不吹';t识别修改后的实体,javascript,entity,breeze,savechanges,Javascript,Entity,Breeze,Savechanges,我有一个breeze实现,它接受一个location对象并在UI上显示属性。我对一些属性进行了更改并尝试保存更改,但breeze没有将实体识别为已更改。以下是我的代码: [HttpGet] [CustomAuthorize(Claims = "permission:CanViewLocationAttributes")] public Location GetLocationById(int clientId, int locationId) {
[HttpGet]
[CustomAuthorize(Claims = "permission:CanViewLocationAttributes")]
public Location GetLocationById(int clientId, int locationId)
{
//returns a single Location object
}
以下是检索实体并保存实体的客户端功能:
function getLocationById(clientId, locationId) {
var self = this;
return EntityQuery.from('GetLocationById')
.withParameters({ clientId: clientId, locationId : locationId })
.using(self.manager)
.execute()
.then(querySucceeded, this._queryFailed);
function querySucceeded(data) {
if (data.results.length > 0) {
return data.results[0];
}
logSuccess(localize.getLocalizedString('_RetrievedLocations_'), locations, true);
}
}
function saveLocationSettings(clientId) {
var self = this;
var saveOptions = this.manager.saveOptions.using({ resourceName: "SaveLocationSettings", allowConcurrentSaves: true });
var entitiesToSave = self.manager.getChanges();
return self.manager.saveChanges(entitiesToSave, saveOptions).then(saveSucceeded, saveFailed);
}
我的问题是这里entitiesToSave的值是0,即使在我更改UI中的字段并保存它们之后也是如此
以下是如何将实体绑定到角度模型:
function getLocationDetails() {
clientcontext.location.getLocationById($route.current.params.clientId, $route.current.params.id)
.then(function (data) {
basicLocationSettings.id = data.locationId;
basicLocationSettings.parent = data.fkParentLocationId;
basicLocationSettings.locationType = data.locationType;
basicLocationSettings.locationName = data.locationName;
basicLocationSettings.locationDisplayName = data.locationDisplayName;
basicLocationSettings.locationCode = data.locationCode;
basicLocationSettings.isActive = data.activeStatus;
basicLocationSettings.timeZone = data.fkTimeZoneId;
basicLocationSettings.usesAppointments = data.usesAppointments;
basicLocationSettings.availabilityWindowDays = data.availabilityWindowDays;
basicLocationSettings.appointmentCutOffDays = data.appointmentCutOffDays;
basicLocationSettings.dailySummaryEmailTime = data.dailySummaryEmailTime;
basicLocationSettings.reminderBeforeApptEmailTime = data.reminderBeforeApptEmailTime;
basicLocationSettings.saveLocationSettings = function () {
clientcontext.location.saveLocationSettings($route.current.params.clientId);
}
});
}
谁能解释我做错了什么?这是我第一次尝试breeze,我有点被困在这里。看起来您正在将breeze位置实体的属性值复制到名为“basicLocationSettings”的pojo对象变量中。对basicLocationSettings的任何更改都不会被breeze实体管理器跟踪,也不会反映在源breeze实体中。您需要将实际的breeze实体绑定到UI,以便用户数据输入直接修改实体属性值。我修改了代码,如下所示,现在保存工作正常:
function getLocationById(clientId, locationId) {
var self = this;
var location = null;
return EntityQuery.from('GetLocationById')
.withParameters({ clientId: clientId, locationId : locationId })
.using(self.manager)
.execute()
.then(querySucceeded, this._queryFailed);
function querySucceeded(data) {
if (data.results.length > 0) {
location = data.results[0];
}
logSuccess(localize.getLocalizedString('_RetrievedLocations_'), locations, true);
return location;
}
}
注意,我正在返回一个location对象,在我的控制器中,我将location对象绑定到我的POJO
function getLocationDetails() {
clientcontext.location.getLocationById($route.current.params.clientId, $route.current.params.id)
.then(function (data) {
basicLocationSettings.location = data;
basicLocationSettings.saveLocationSettings = saveLocationSettings;
});
}
现在,当我调用saveChanges()时,我将location对象传递到存储库:
function saveLocationSettings() {
clientcontext.location.saveLocationSettings(basicLocationSettings.location);
}
但是,难道没有一种方法可以使用某种viewmodel进行UI绑定吗?我的breeze查询运行在一个单独的存储库中,我使用一个单独的控制器与创建pojo对象的UI进行通信。在该设计中,如何将breeze实体直接绑定到UI?这是一个单独的问题,应该在angularjs标记下提出。我会尽力帮忙的,但我对angular没有太多经验。谢谢你的提示,我发现了我做错了什么,并修复了它。我将把答案分开。正如你所说的,不是微风造成了麻烦,而是棱角分明。