【问题标题】:this[propertyName] is not a function in breeze.debug.jsthis[propertyName] 不是微风.debug.js 中的函数
【发布时间】:2013-05-26 10:47:03
【问题描述】:

我正在使用热毛巾模板并通过微风扩展了它的功能。我已经使用了breath.partial-entities.js 文件将微风实体转换为适当的dto,可以被淘汰的observables使用,如下所示。

function dtoToEntityMapper(dto) {
            var keyValue = dto[keyName];
            var entity = manager.getEntityByKey(entityName, keyValue);
            if (!entity) {
                // We don't have it, so create it as a partial
                extendWith = $.extend({ }, extendWith || defaultExtension);
                extendWith[keyName] = keyValue;
                entity = manager.createEntity(entityName, extendWith);
            }
            mapToEntity(entity, dto);
            entity.entityAspect.setUnchanged();
            return entity;
        }

对于少数实体,它可以正常工作并将微风数据转换为实体,但对于其中一个实体实现失败。相同的模型如下所示。

public class StandardResourceProperty
{
    [Key]
    public int Id { get; set; }
    public string Name { get; set; }
    public int StandardResourceId{ get; set; }
    public int InputTypeId{ get; set; }
    public int ListGroupId{ get; set; }
    public string Format{ get; set; }
    public string Calculation{ get; set; }
    public bool Required{ get; set; }
    public int MinSize{ get; set; }
    public int MaxSize{ get; set; }
    public string DefaultValue{ get; set; }
    public string Comment { get; set; }

    public virtual StandardResource AssociatedStandardResource { get; set; }
    public virtual List AssociatedList { get; set; }
}

我得到的错误是 TypeError: this[propertyName] 不是函数 [打破这个错误]

此属性名称;

breeze.debug.js(第 13157 行)

]

有代码

proto.setProperty = function(propertyName, value) {
        this[propertyName](value);
        // allow set property chaining.
        return this;
    };

请告诉我。实现也可能出现什么问题,如果我能就如何调试和跟踪此类问题获得更多建议,那就太好了。

【问题讨论】:

    标签: asp.net-mvc-4 breeze hottowel


    【解决方案1】:

    让我们备份。我不明白您所说的“将微风实体转换为可供淘汰可观察对象使用的适当 dto”是什么意思。 Breeze 实体已配置为 KO observables(假设您使用的是默认的 Breeze 模型库配置)。你想做什么?

    我怀疑您正在关注 Code Camper Jumpstart 课程,它会执行 getSessionPartials 投影查询。该查询(与所有投影一样)返回 DTO - 而不是实体 - 并使用 dtoToEntityMapper 方法将它们映射到 Session 实体。

    CCJS dtoToEntityMapper 方法不能用于实体。它用于从 DTO 转换为实体,并将 DTO - 不是实体 - 作为输入。

    再见 dtoEntityMapper

    dtoToEntityMapper 方法早于 Breeze 通过将 .toType('StandardResourceProperty') 添加到投影查询来自动进行投影到实体映射的能力。

    下面是 CCJS getSessionPartials 查询现在的样子:

    var 查询 = 实体查询 .from('会话') .select('id, title, code, speakerId, trackId, timeSlotId, roomId, level, tags') .orderBy(orderBy.session) .toType('会话');

    如果你这样做,请务必在自定义构造函数中将isPartial标志的默认状态设置为true(参见model.js

    metadataStore.registerEntityTypeCtor( '会话',函数(){ this.isPartial = true; }, sessionInitializer);

    注意 this.isPartial = true 是 CCJS 示例的reverse,默认为 false

    确保在查询或创建完整实体时设置isPartial(false)。在 CCJS 中有两个地方可以做到这一点:在 getSessionById 的成功回调和 createSession 中,这将变成:

    var createSession = 函数 () { 返回 manager.createEntity(entityNames.session, {isPartial: false}); };

    【讨论】:

    • 这引发了另一个问题。首次加载数据时,所有实体都有isPatrial == true(来自ctor)。然后,如果我们选择加载实体的所有数据(我们称之为e),我们将其设置为e.isPartial(false)。如果我们然后重新加载(即用forceRemote 调用getSessionPartials 来设置true),e 的数据被删除,部分数据从服务器获取并分配给e,但e.isPartial 仍然存在错误的。因此,如果我们现在尝试再次通过 id 加载 e 的数据,app 会看到 e 是部分的并且不会刷新它。
    • 我最终在本地查询所有实体,然后将它们分离,然后再进行重新查询。这很聪明吗?
    猜你喜欢
    • 2012-12-20
    • 2013-06-06
    • 2015-02-27
    • 2021-03-31
    • 2018-01-19
    • 2012-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多