【发布时间】:2012-07-09 20:27:09
【问题描述】:
我在 .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)。更改该值将触发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); }; -
定义我自己的 map 函数并将其传递给 upshot:
window.Request = function (initialData) { var self = this; upshot.observability.configuration.map(initialData, upshot.type(Request), map, self); };
所有方法的映射似乎都是正确的,除了父实体不知道在其子实体中所做的修改。甚至可以进行儿童跟踪吗?
【问题讨论】:
标签: upshot single-page-application