【问题标题】:upshot js change tracking in child entities子实体中的结果 js 更改跟踪
【发布时间】: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


    【解决方案1】:

    好的,我终于找到了问题所在。事实证明,当存在 3 个嵌套实体的层次结构时(即 Request -> InfoCard -> InfoField,此行为是可重现的。修改 InfoField 的值并未反映在父实体中。

    经过数小时的结果调试,我发现罪魁祸首是 upshot.js 中的_addTrackingRecursive 方法。将obs.track(obj, this._getTracker(), this._entityType); 调用替换为obs.track(obj, this._getTracker(), type); 解决了嵌套更改跟踪问题。

    【讨论】:

      猜你喜欢
      • 2011-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-08
      • 2011-10-27
      • 1970-01-01
      相关资源
      最近更新 更多