我在 .NET 中定义了以下模型:
Public Class Request
<Key()>
Public Property RequestId As String
Public Property Description As String
Public Property InfoCards As List(Of InfoCard)
End Class
Public Class InfoCard
<Key()>
Public Property InfocardId As String
Public Property Description As String
Public Property RequestId As String
End Class
InfoCard 上的ReqeuestId属性使 EF Code First 可以生成数据库。然后我使用UpshotContext
帮助器生成 JavaScript 模型,如下所示:
Html.UpshotContext(bufferChanges:= true) _
.DataSource(Of UpshotTest.UpshotTest.RequestController)(Function(x) x.GetRequests()) _
.ClientMapping(Of UpshotTest.Models.Request)("Request") _
.ClientMapping(Of UpshotTest.Models.InfoCard)("InfoCard")
这很好地生成了所有模型,当我调用refresh
结果数据源时,数据按预期检索。
我面临的问题Request.InfoCards(0).Description
是当我尝试修改子对象(eq )的属性时。更改该值将触发 中的更改InfoCard
,但不会触发Request
实体中的更改。因此,调用Request.IsUpdated()
将返回false,而调用Request.InfoCards(0).IsUpdated()
将返回true。
upshot 不知道如何跟踪子实体的变化吗?还是客户端的映射有问题?到目前为止,我已经尝试了几种映射:
手动映射所有属性:
window.Request = function (initialData) { var self = this; self.RequestId = ko.observable(initialData.RequestId); self.Description = ko.observable(initialData.Description); self.InfoCards = ko.observableArray(ko.utils.arrayMap(initialData.InfoCards, function (data) { return new window.InfoCard(data); })); upshot.addEntityProperties(self, "Request:#UpshotTest.Models"); };
使用
upshot.map
:window.Request = function (initialData) { var self = this; upshot.map(initialData, upshot.type(Request), self); };
定义我自己的地图函数并将其传递给结果:
window.Request = function (initialData) { var self = this; upshot.observability.configuration.map(initialData, upshot.type(Request), map, self); };
所有方法的映射似乎都是正确的,除了父实体不知道在其子实体中所做的修改。儿童跟踪甚至可能吗?