Aurelia-Typescript-在复杂数据结构中设置单个值时遇到问题
我一直有各种各样的麻烦 我有一个实例化的类client.ts,它的结构中有另一个类-address.ts。在Address中,我有addressLocation.ts,在这里我需要将stateShortName设置为VIC,我需要在该类上设置一个值,我对此有问题 客户端类是:Aurelia-Typescript-在复杂数据结构中设置单个值时遇到问题,typescript,aurelia,Typescript,Aurelia,我一直有各种各样的麻烦 我有一个实例化的类client.ts,它的结构中有另一个类-address.ts。在Address中,我有addressLocation.ts,在这里我需要将stateShortName设置为VIC,我需要在该类上设置一个值,我对此有问题 客户端类是: import { Serializable } from "../../../../services/serializable/Serializable" import { AddressDetails
import { Serializable } from "../../../../services/serializable/Serializable"
import { AddressDetails } from "../address/addressDetails"
import { JobDetails } from "../../jobs/jobDetail/jobDetails"
export class ClientDetails implements Serializable<ClientDetails> {
clientId: number;
clientNo: number;
company: boolean;
companyName: string;
abn: string;
isWarrantyCompany: boolean;
requiresPartsPayment: boolean;
clientFirstName: string;
clientLastName: string;
email: string;
mobilePhone: string;
phone: string;
notes: string;
address: AddressDetails = "new AddressDetails";
jobs: JobDetails[];
bankName: string;
bankBSB: string;
bankAccount: string;
active: boolean;
deActivated: string;
activity: boolean;
creatorId: number;
creatorName: string;
dateCreated: string;
updatorId: number;
updatorName: string;
dateUpdated: string;
deserialize(input) {
this.clientId = input.clientId;
this.clientNo = input.clientNo;
this.company = input.company;
this.companyName = input.companyName;
this.abn = input.abn;
this.isWarrantyCompany = input.isWarrantyCompany;
this.requiresPartsPayment = input.requiresPartsPayment;
this.clientFirstName = input.clientFirstName;
this.clientLastName = input.clientLastName;
this.email = input.email;
this.mobilePhone = input.mobilePhone;
this.phone = input.phone;
this.notes = input.notes;
this.bankName = input.bankName;
this.bankBSB = input.bankBSB;
this.bankAccount = input.bankAccount;
this.active = input.active;
this.deActivated = input.deActivated;
this.activity = input.activity;
this.creatorId = input.creatorId;
this.creatorName = input.creatorName;
this.dateCreated = input.dateCreated;
this.updatorId = input.updatorId;
this.updatorName = input.updatorName;
this.dateUpdated = input.dateUpdated;
if (input.jobs) {
this.jobs = new Array<JobDetails>();
for (let count = 0; count < input.jobs.length; count++) {
let job = new JobDetails;
this.jobs.push(job.deserialize(input.jobs[count]));
}
}
if (input.address) {
this.address = new AddressDetails;
this.address.deserialize(input.address);
}
return this;
}
deserializeAddressStateShortName(input) {
}
}
它将address类设置为new AddressDetails
地址类别如下所示:
import { Serializable } from "../../../../services/serializable/Serializable"
import { AddressLocation } from "./addressLocation"
export class AddressDetails implements Serializable<AddressDetails> {
address1?: string;
address2?: string;
addressLocation: AddressLocation;
deserialize(input) {
//console.log("INPUT: ", input)
this.address1 = input.address1;
this.address2 = input.address2;
if (input.addressLocation) {
this.addressLocation = new AddressLocation;
this.addressLocation.deserialize(input.addressLocation);
}
return this;
}
}
Address已将addressLocation设置为新的addressLocation
import { Serializable } from "../../../../services/serializable/Serializable"
export class AddressLocation implements Serializable<AddressLocation> {
addressLocationId?: number;
suburb?: string;
postcode?: string;
stateShortName?: string;
set stateName(name: string) {
this.stateShortName = name;
}
deserialize(input) {
this.addressLocationId = input.addressLocationId;
this.suburb = input.suburb;
this.postcode = input.postcode;
this.stateShortName = input.stateShortName;
return this;
}
}
每个都可以使用反序列化函数进行初始化
我执行一个fetch,并使用来自fetch-in客户机的数据,然后填充address和addressLocation
好的。当我获取并使用this.client.deserializedata设置客户机对象时,它会工作,并且对象会被填充
我不想为了在addressLocation中设置一个值而遍历整个值集
使用client=new ClientDetails;创建客户机后,我该如何操作;,在this.client.address.addressLocation.stateShortName中设置stateShortName的值?我不知道如何仅解析该值?如果我正确理解了您的问题,您希望在初始化新类之后和反序列化任何内容之前在成员对象中赋值。在这种情况下,类成员定义必须是address=newaddressdetails;没有标志。目前,您的成员变量是一个字符串 将其公开并只设置值?this.client.address.addressLocation.stateShortName='someName'说真的,你已经为此奋斗了这么久了。。你能为它创建一个要点吗?这样你就可以在这篇文章中看到它,并添加相关的html/js文件。你问的问题@aurelia Discussion已经得到了回答。