gpt4 book ai didi

knockout.js - 不能设置集合导航属性

转载 作者:行者123 更新时间:2023-12-02 02:03:18 24 4
gpt4 key购买 nike

我一直在构建我的第一个 SPA 应用程序,从 John Papa 的 jumpstart 开始出色的工作。

我遇到的问题是,当我尝试通过 breeze 执行 Expand,或者只是选择所有字段时,在映射我的子集合期间,我从 Breeze 收到了一个问题。 newValue.entityAspect 未定义

如果我通过 select 子句通过我的 api 查询,一切都很好,如果我直接调用表,直接“位置”,我会在 chartVal 对象上得到导航错误。 enter image description here enter image description here

var query = EntityQuery.from('Positions')
//.select('id, endDate, gauge, hoursPerWeek, memberId, title, summary, startDate, totalHours, weightedHours, company, compensation')
.where('memberId', '==', id)
.expand('Company, ChartVals')
.orderBy(orderBy.positions);

return manager.executeQuery(query)
.then(querySucceeded)
.fail(queryFailed);

function querySucceeded(data) {
var list = partialMapper.mapDtosToEntities(manager, data.results, entityNames.position, 'id');
if (observables) {
observables(list);
}

上面的查询会成功,然后调用 MapDtosToEntities(由 John Papa 提供)

函数 mapDtosToEntities(manager, dtos, entityName, keyName, extendWith) { 返回 dtos.map(dtoToEntityMapper);

        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;
}

function mapToEntity(entity, dto) {
// entity is an object with observables
// dto is from json
for (var prop in dto) {
if (dto.hasOwnProperty(prop) && prop !="entityAspect") {
entity[prop](dto[prop]); <-- tanks here on children
}
}
return entity;
}
}


/// <summary>
/// TODO: Update summary.
/// </summary>
public class Position : PersistableObject
{
public int CompanyId { get; set; }

/// <summary>
/// Weighted hours based on Half-Life.
/// </summary>
public int CreditMinutes { get; set; }

public int? CompensationId { get; set; }

public DateTime? EndDate { get; set; }
/// <summary>
/// Code to hold measure of completeness. 10 = complete 0 = not complete.
/// </summary>
public int Gauge { get; set; }

public int? HoursPerWeek { get; set; }

public bool IsCurrent { get; set; }

[StringLength(40)]
public string LinkedInId { get; set; }

[Required]
public int MemberId { get; set; }

[StringLength(40)]
public string Title { get; set; }

[StringLength(400)]
public string WeightedWords { get; set; }

/// <summary>
/// Adjusted Experience score Based on half life
/// </summary>
public int Score { get; set; }

[Required]
[StringLength(2000)]
public string Summary { get; set; }

public DateTime StartDate { get; set; }

public decimal? SalaryEnd { get; set; }

/// <summary>
/// Hourly salary - let users enter hourly, monthly, annual etc
/// </summary>
public decimal? SalaryStart { get; set; }

public decimal TotalHours { get; set; }

/// <summary>
/// Total Man-hours Multiplied by Gauge reading
/// </summary>
public decimal WeightedHours { get; set; }

public int VisibilityId { get; set; }

public Company Company { get; set; }

public Member Member { get; set; }

public virtual Compensation Compensation { get; set; }

public virtual ICollection<Project> Projects { get; set; }

public virtual ICollection<Tag> Tags { get; set; }

public virtual ICollection<ChartVal> ChartVals { get; set; }

}


public class ChartVal : PersistableObject
{
[Required]
[StringLength(40)]
public string Key { get; set; }

public double Value { get; set; }

public string Percentage { get; set; }

public int PositionId { get; set; }

public virtual Position Position { get; set; }
}

感谢您花时间查看我的问题。感谢您的宝贵时间!

最佳答案

我也看到了。我相信解决方案将涉及检测该属性是否是一个集合并对其进行迭代以逐一添加项目。我还没有尝试这样做,因为我还在尝试决定这是否是正确的事情

我并不打算将其本身作为一个答案,而是表明其他人已遵循与发布者相同的轨道,并且会对社区对此的任何回应感兴趣。

关于knockout.js - 不能设置集合导航属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16152545/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com