微风第二个查询扩展实体属性只加载 [英] Breeze Extended Entity Property Only Loads on Second Query
问题描述
希望有人有更好的洞察微风的扩展实体,因为我难倒!所以,我创建了一个局部类(WO_Rout)在服务器端(使用微风的API网页API),并创建了一个名为AssetJobEqNo属性。
Hopefully someone has a better insight into Breeze's Extended entities, because I'm stumped! So, I have created a partial class (WO_Rout) on the server side (Web API using Breeze's API) and created a property named "AssetJobEqNo".
我已阅读并遵循微风的文档与无济于事这里。继引导我创建了一个构造这个特殊的实体WO_Rout像这样:
I have read and followed Breeze's documentation here with no avail. Following the guide I have created a constructor for this particular entity "WO_Rout" like so:
var assets = function () {
this.AssetJobEqNo = '';
};
var serviceName = 'cms8/workorders';
var manager = new breeze.EntityManager({
serviceName: serviceName
});
var store = manager.metadataStore;
store.registerEntityTypeCtor('WO_Rout', assets);
当我查询我的控制器这个特殊的财产AssetJobEqNo发送,并在客户端上的JSON原始结果可见。
When I query my controller this particular property "AssetJobEqNo" is sent and seen in the JSON raw results on the client side.
所以....这里是怪异的一部分我想不通。如果我运行一个查询绑定到一个按钮在我的UI财产被加载并在对象给我分配了,但它仍然是一个空字符串的默认值,它永远不会加载。然后我跑完全相同的查询再次抓住了相同的实体,这时间的价值是存在的。
So....here is the weird part I can't figure out. If I run a query tied to a button on my UI the property IS loaded and in the object I assigned it, BUT it's still the default value of an empty string, it never loads. Then I run the EXACT same query again grabbing the same entities and this time the value IS there.
在最后,我很困惑,为什么这个扩展实体的财产不被填充在第一查询,但如果我运行完全相同的查询它加载第二次?
In conclusion, I'm confused as to why this extended entity's property is not being filled the first query but if I run the exact same query it loads the second time?
希望这一切是很有意义的。
Hope this all makes sense.
DataService的功能:
function getWorkOrder(reqNo) {
if (reqNo > 0) {
var query = breeze.EntityQuery.from("GetWorkOrders");
query = query.where("req_no", "==", reqNo)
.expand(["WO_RtHelp.WO_Rout", "WO_RtHelp.WO_Rout.eqptmast", "WO_RtHelp.WO_Act.WO_Resources.persmast", "WO_RtHelp.WO_Act.WO_Resources.Kits", "WO_RtHelp.WO_Act.Activity", "WO_RtHelp.WO_Act.WO_Resources.customer", "WO_RtHelp.WO_Act.WO_Resources.eqptmast", "WO_RtHelp.WO_Act.WO_Resources.invsite.invmast", "WO_RtHelp.WO_Act.WO_Resources.crew"])
return manager.executeQuery(query);
} else {
return throwNotification('Please enter a Work Order number.');
}
}
有关成功查询的控制器功能
function querySucceeded(data) {
$scope.WorkOrder = {};
if (data.results.length === 0) {
sysErrorNotification('No Work Order with System #' + $scope.workOrderSearchNumber);
}
else {
$scope.WorkOrder = data.results[0];
$scope.myData = $scope.WorkOrder.WO_RtHelp;
$('#bottomNav a[href="/WorkOrders/#woMain"]').tab('show');
resetDataSources();
$scope.$apply();
}
}
我使用的微风,角,Q,和jQuery
推荐答案
所以经过骂个不停几天我相信我已经解决了这个问题。在之后的实体的创建和合并过程,从物化查询时后,我发现在我的财产正在被有从的扩展实体属性的默认值rawEntity覆盖。
So after a few days of hammering away I believe I have resolved the problem. After following the entity in it's creating and merging process, when materializing from a query, I found where my property was being overwritten by the "rawEntity" which has the default value from the extended entity property of "".
我使用的微风1.4.2和breeze.debug.js调试,发现上线14854的功能proto.initializeFrom是导致此问题。
I'm using Breeze 1.4.2 and debugging with breeze.debug.js and found on line 14854 the function proto.initializeFrom is causing this problem.
这里是我做过什么来解决这个问题:
proto.initializeFrom = function (rawEntity) {
// HACK:
// copy unmapped properties from newly created client entity to the rawEntity.
// This is so that we don't lose them when we update from the rawEntity to the target.
// Something that will occur immediately after this method completes.
var that = this;
this.entityType.unmappedProperties.forEach(function(prop) {
var propName = prop.name;
that[propName] = rawEntity[propName]; // CassidyK
//rawEntity[propName] = that[propName]; // Breeze
});
if (!this._backingStore) {
this._backingStore = { };
}
};
我会继续,如果我找到我这里来实现修复任何问题这个更新。
I'll keep this updated if I find any problems with the fix I implemented here.
这篇关于微风第二个查询扩展实体属性只加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!