我有一个视图模型,它包含一个类数组。该模型包含一个名为“isJobber”的布尔值。该模型中的数组根据“isJobber”值(加上一些布尔值)设置一些更多的布尔值,以确定用户是否可以编辑某些特定字段。
我发现可编辑/不可编辑字段存在一些不一致之处,因此我在模型中的数组中的每个项目中添加了“debug”属性。
debug属性包含:
debug = isJobber.ToString();
我的模型有“isJobber”属性。模型返回true,而debug属性返回false。
我正在使用Knockout来查看chrome调试工具中的所有这些值。
这有多可能。 isJobber值永远不会从用于填充数组的时间更改为在父模型中填充的时间。以下是所有代码:
var isJobber = _storeRepo.Query().FirstOrDefault(s => s.OwnerID == ownerId).Jobber;
var goalViewModel = goals.Select(g => new GoalViewModel {
GoalId = g.GoalId,
MonthName = GetMonth(g.Month),
Month = g.Month,
LYMonthSales = g.LYMonthSalesAdjusted,
LYMonthSalesActual = g.LYMonthSalesActual,
CYMonthGoal = g.CYMonthGoal,
CYMonth = g.CYMonthAdjusted,
CYMonthActual = g.CYMonthActual,
ExpoDollars = g.ExpoDollars,
LYSalesEditable = isJobber && (currentDate.Year < 2014 || (activeMonth == null && currentDate.Month <= g.Month) || activeMonth <= g.Month),
CYSalesEditable = isJobber && currentDate.Year >= 2014 && activeMonth != null && activeMonth == g.Month,
GoalEditable = (lastProcessedMonth == null || lastProcessedMonth < g.Month),
Debug = "currentDate: " + currentDate.ToShortDateString() + "; isJobber: " + isJobber + "; activeMonth: " + activeMonth + "; Month: " + g.Month + "; lastProcessedMonth: " + lastProcessedMonth
}).ToList();
return View(new EarnbackModel {
EnrollmentId = enrollment.EnrollmentId,
CustomerName = enrollment.Customer.CustomerName,
TotalPackagePrice = packages.Where(p => p.CancellationDate == null).Sum(p => p.Price),
EarnbackCap = enrollment.EarnbackCap ?? 0,
EarnbackCapMax = isJobber ? 1000000m : 5000m,
DefaultGoalPercent = 7,
Ars = arSelections.ToList(),
Goals = goalViewModel,
IsJobber = isJobber,
AvailableStores = stores,
LastProcessedMonth = lastMonth,
});
以下是chrome开发人员工具的输出:
viewModel.IsJobber()
true
viewModel.Goals()[0].Debug()
"currentDate: 12/22/2013; isJobber: False; activeMonth: ; Month: 1; lastProcessedMonth: "
我通过Chrome开发者工具注意到的一件事,我们托管此网站的服务器认为它是12/22/2013 ...不要认为它对我的房产价值有任何影响,但值得注意......
回应PW Cad的评论/问题:这是淘汰赛的cshtml代码。这是否回答了关于isJobber可观察的问题?既然它在视图模型中,那么它是否会使它成为可观察的()?顺便说一下,我会开始研究jsFiddle,以为我以前从未这样做过。
此外,这在我的开发(localhost)和测试网站中运行良好。只有生产不起作用......
var raw = @Html.Json(Model);
viewModel = ko.mapping.fromJS(raw);
这是jsFiddle,但我不知道如何在没有实际数据的情况下让它变得有价值......
以下是我的模特:
public class EarnbackModel
{
public EarnbackModel()
{
Ars = new List<ArSelectionViewModel>();
Goals = new List<GoalViewModel>();
AvailableStores = new List<StoreViewModel>();
}
public int EnrollmentId { get; set; }
public string CustomerName { get; set; }
public decimal TotalPackagePrice { get; set; }
public decimal EarnbackCap { get; set; }
public decimal EarnbackCapMax { get; set; }
public decimal DefaultGoalPercent { get; set; }
public IList<ArSelectionViewModel> Ars { get; set; }
public IList<GoalViewModel> Goals { get; set; }
public bool IsJobber { get; set; }
public IList<StoreViewModel> AvailableStores { get; set; }
public NewARViewModel NewAr { get; set; }
public int LastProcessedMonth { get; set; }
}
public class GoalViewModel
{
public bool MonthClosed { get; set; }
public int GoalId { get; set; }
public string MonthName { get; set; }
public int Month { get; set; }
public decimal LYMonthSales { get; set; }
public decimal LYMonthSalesActual { get; set; }
public decimal CYMonthGoal { get; set; }
public decimal? CYMonth { get; set; }
public decimal? CYMonthActual { get; set; }
public decimal? ExpoDollars { get; set; }
public bool LYSalesEditable { get; set; }
public bool CYSalesEditable { get; set; }
public bool GoalEditable { get; set; }
public string Debug { get; set; }
}
答案 0 :(得分:2)
如果它在开发中工作但不在生产中,那么看起来发布配置正在改变某些内容或者生产环境或部署包有问题。也许尝试打包和重新部署。如果这不起作用,请尝试部署到另一台服务器。