import { Board } from './board';
export class Notification {
id : number ;
startDate : Date = null;
endDate : Date = null;
message : string = '';
notificationBoards: Board[] ;
}
董事会课程
export class Board {
id : number = 0;
name : string = '';
createDate : Date = null;
createdBy : number ;
}
对应类为
message.component.ts
///..
submitForm(obj) {
console.log("obj - "+obj);
let notificationObj:Notification = new Notification();
let selectedBoard: Board[];
notificationObj.startDate = obj.startDate;
notificationObj.endDate = obj.endDate;
notificationObj.message = obj.message;
notificationObj.notificationBoards = obj.board;
console.log("notificationObj.notificationBoards"+notificationObj.notificationBoards.length);
for (let i = 0; i < notificationObj.notificationBoards.length; i++) {
console.log(":::"+notificationObj.notificationBoards[i] +":::");
}
...///
我能够添加通知,但无法在通知对象内添加板obj。板是板列表。 obj.board-是一个数组{10,20,...},它是boardId。 我想将此数组添加到Board []并发送到服务层。 让selectBoard:Board [];是板列表,我想将notificationObj.notificationBoards [i]推送到selectedBoard [i],依此类推。 基本上是想将数组添加到对象列表Board []。有人可以帮忙吗?
您的 obj.board 是数字的简单数组(如您所解释的,boardIds), notificationObj.notificationBoards 是 Board 对象的数组
Typescript不允许您将 Board 类类型的对象数组转换为数字值数组。
您将必须将一种数组类型映射到另一种数组,就像这样。
notificationObj.notificationBoards = obj.board.map(boardId=>{
let boardObj:Board = new Board();
boardObj.id = boardId; //since we have only one element (boardId), other fields of board object are not set.
return boardObj;
});