Не уверен, что слово «впрыскивать» - правильное слово. Я все еще довольно новичок в программировании, и я могу спросить моего отца, который работает вместе со мной, но я хотел попытаться ответить на вопрос stackoverflow. Извините, если это окажется непонятным.
Справочная информация:
Я создаю таблицу досок с всплывающим диалоговым окном для добавления дополнительных досок к предложению. Таблица извлекает из 3 разных наборов данных offer.ts ,boards.ts, offer-board.ts Данные передаются нормально, проблема в том, что они отображаются в таблице.
Отображаемые данные связаны в const proposalBoard = new ProposalBoard( ... )
с элементами из offer-board.ts, но элементы EndDate и StartDate взяты из offer.ts, а не offer-board.ts.
Итак, вопрос в следующем: Могу ли я вставить элементы EndDate и StartDate в offer-board.ts? Если да, то как?
edit-offer.component. html
<ng2-smart-table [settings]="proposalBoardSettings" [source]="proposal.Boards">
</ng2-smart-table>
<div class="col-sm-2">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#add-boards-modal"
(click)="showBoardSelectDialog">+ Add Boards</button>
<div *ngIf='proposal.Boards'>
<app-boardselectdialog (selectedBoards)="addBoards($event)" [boards]="proposal.Boards"></app-boardselectdialog>
</div>
</div>
edit-offer.component.ts
export class EditProposalComponent implements OnInit {
boards: any = {};
proposal: any = {};
proposalBoardSettings = {
actions: false,
columns: {
StructureNumber: {
title: 'StructureNum',
filter: false
},
BoardName: {
title: 'BoardName',
filter: false
},
StartDate: {
title: 'Start Date',
filter: false
},
EndDate: {
title: 'End Date',
filter: false
},
Status: {
title: 'Status',
filter: false
},
Cost: {
title: 'Cost',
filter: false
},
Price: {
title: 'Price',
filter: false
}
}
};
addBoards(boards: any) {
const newProposalBoards: ProposalBoard[] = [];
boards.forEach(element => {
// loops through the boards returned from the dialog
// tslint:disable-next-line: max-line-length
console.log('Dialog Board', element);
// creates new ProspoalBoards objects from Boards objects returned from Dialog
const proposalBoard = new ProposalBoard(
element.Name,
element.StructureNumber,
element.Cost,
element.EndDate, //<- these are squigled
element.StartDate, //<- these are squigled
);
// adds new ProposalBoards to the array
newProposalBoards.push(proposalBoard);
});
console.log('ProposalBoards', newProposalBoards);
// replace Boards with new array of boards to show on the table
this.proposal.Boards = newProposalBoards;
this.UpdateCosts();
this.UpdatePrice();
console.log('Proposals');
}
}
offer-board.ts
export class ProposalBoard {
BoardName: string;
StructureNumber: string;
Cost: number;
constructor(name: string,
structureNumber: string,
cost: number,
) {
this.StructureNumber = structureNumber;
this.BoardName = name;
this.Cost = cost;
}
}
offer.ts
export class Proposal {
EndDate: string;
StartDate: string;
constructor(
endDate: string,
startDate: string,
) {
this.EndDate = endDate;
this.StartDate = startDate;
}
}