我从一位前开发者那里继承了一个应用程序,我的所有调试功能都已经耗尽了。这个应用程序是我第一次接触到Typescript,所以我也感觉有点失落。我也找不到任何与StackOverflow相关的内容,所以这是我的问题:
我有一个名为“Task”的实体,其在C#中的定义如下:
public class Task : ModelBase
{
public Task()
{
FiscalYears = new List<TaskFy>(28);
Flags = new List<TaskFlags>();
}
[Required, AuditField("Project", typeof(Project))]
public Guid Project_Id { get; set; }
public virtual Project Project { get; set; }
public Guid ScenarioId { get; set; }
[AuditField("Active Status")]
public bool IsActive { get; set; }
[RegularExpression(@"^[A-z0-9]+$", ErrorMessage = "A Task # must be alphanumeric.")]
[Required, MaxLength(4), AuditField("Task Name"), AuditDisplay]
public string TaskName { get; set; }
[Required, MaxLength(100), AuditField("Title")]
public string Title { get; set; }
[AuditField("Description")]
public string Description { get; set; }
[AuditField("ATO", typeof(Dropdown))]
public Guid TaskAto_Ident { get; set; }
public virtual Dropdown Ato { get; set; }
[AuditField("DTO", typeof(Dropdown))]
public Guid? DtoId { get; set; }
public virtual Dropdown Dto { get; set; }
[AuditField("Performer", typeof(Performer))]
public Guid Performer_Id { get; set; }
public virtual Performer Performer { get; set; }
//<snip, several string fields here>
public virtual List<TaskFy> FiscalYears { get; set; }
public virtual List<Workpackage> Workpackages { get; set; }
public virtual List<TaskFlags> Flags { get; set; }
}
当请求任务时,返回的任务不为空,它实际上是一个完全有效的任务(通过调试确认)。我也在这里的Typescript中有了定义:
export interface ITask extends ng.resource.IResource<ITask> {
id: string;
projectId: string;
isActive: boolean;
taskName: string;
title: string;
description: string;
ato: IDropdown;
atoId: string;
dto: IDropdown;
dtoId: string;
performerId: string;
performer: IPerformer;
//<snip, same string fields here>
fiscalYears?: ITaskFy[];
}
taskCtrl.ts如下:
export default class TasksCtrl {
static $controllerAs = 'p';
private isEditing: boolean;
private taskId: string;
private item: ITask;
private children: IByFlagsResult[];
private flags: ITaskFlags;
private objective: ITaskObjective;
private tso: IPoc;
private poc: ITaskPerformingOrg;
private fyStartYear: number;
static $inject = ['$stateParams', '$state', '$modal', 'Task', 'TaskFlags', 'TaskObjective',
'TaskPerformingOrg', 'Toast', 'Login', 'KeyGen', 'fyStartYear', 'taskInfo', 'dropdowns'];
constructor(private $stateParams: ITaskParams, private $state: ng.ui.IStateService,
private $modal: ng.ui.bootstrap.IModalService, private task: ITaskResource,
private taskFlags: ITaskFlagsResource, private taskObjective: ITaskObjectiveResource,
private taskPerformingOrg: ITaskPerformingOrgResource, private toast: IToast,
private login: ILogin, private keygen: IKeyGen,
fyStartYear: number, taskInfo: ITaskResolveResults, private dropdowns: any) {
this.item = taskInfo.task;
this.children = this.keygen.convertTreeToLinkElements(taskInfo.children, 'workpackage');
this.flags = taskInfo.flags;
this.objective = taskInfo.objectives;
this.tso = taskInfo.tso;
this.poc = taskInfo.poc;
this.isEditing = taskInfo.isEditing;
this.taskId = this.item.id;
this.fyStartYear = fyStartYear;
}
//<snip, other methods here>
这就是问题 - 我有两个版本的这个项目。有旧的回购和新的回购(旧的回购与Java应用程序一起捣碎,在一个回购中太麻烦了)。如果我尝试运行新的repo版本,那么我最终得到
Error in resource configuration for action `get`. Expected response to contain an object but got an array (Request: {3} {4})
我尝试查看任务时在控制台中。如果我在新的仓库代码运行时打开旧仓库 ,一切都会开始工作,但我所做的更改(对html)不会显示。在我关闭Visual Studio中的新存储库之前,此更改仍然存在。
第二个错误伴随着控制台中的第一个错误:
TypeError: Unable to get property 'task' of undefined or null reference
指着
行this.flags = taskInfo.flags;
调试这表明taskInfo本身为null。这可能是上述错误的结果,但我认为提及可能会有所帮助。
如果您需要任何进一步的信息或代码,请告诉我们。
谢谢你的期待!
编辑:
我已将问题缩小到以下的Typescript块:
if ($stateParams.taskId) {
return task.getByName({
id: $stateParams.taskId,
projectName: $stateParams.projectId,
peName: $stateParams.peId,
pcName: $stateParams.pcId,
scenarioId: login.scenario.id
}).$promise.then((retrievedTask: ITask) => {
var flags = task.getFlags({ id: retrievedTask.id }).$promise.catch(() => []);
var objectives = taskObjective.query({ id: retrievedTask.id }).$promise.catch(() => {
return new taskObjective({ taskId: retrievedTask.id }).$save();
});
var pOrgs = taskPerformingOrg.getByTask({ id: retrievedTask.id }).$promise.catch(() => {
return new taskPerformingOrg({ taskId: retrievedTask.id }).$save();
});
var tso = project.get({ id: retrievedTask.projectId }).$promise.then((project: IProject) => {
return poc.query({ id: project.pocId }).$promise.catch(() => {});
});
var children = workpackage.getByParent({ parentId: retrievedTask.id, scenarioId: login.scenario.id }).$promise.catch(() => [{"error":"Error"}]);
return $q.all([flags, objectives, pOrgs, tso, children]).then(
(<any>_).spread((flags: ITaskFlags, objectives: ITaskObjective,
poc: ITaskPerformingOrg, tso: IPoc, children: ITreeNode[]) => {
visit.createVisit({ itemType: ReportLevel.Task, itemId: retrievedTask.id, scenarioId: login.scenario.id });
angular.extend(promiseResults, {
isEditing: true,
task: retrievedTask,
children: children,
flags: flags,
objectives: objectives,
poc: poc,
tso: tso
});
return promiseResults;
})
).catch((err: any) => console.log(err));
}).catch(() => {
promiseResults.task = <ITask> { id: '404' };
return promiseResults;
});
具体来说,失败的行似乎是:
return $q.all([flags, objectives, pOrgs, tso, children]).then(
(<any>_).spread((flags: ITaskFlags, objectives: ITaskObjective,
poc: ITaskPerformingOrg, tso: IPoc, children: ITreeNode[]) =>
答案 0 :(得分:0)
找出问题所在。事实证明,我从C#实体中删除了Dto字段和DtoId字段,但没有从Typescript定义中删除它们。如果您遇到同样的问题,我强烈建议您在实体定义中逐行查看并尝试确定是否缺少某些内容。