[英]AngularJS - How to add new property to each object in array
我想學習如何將范圍變量推送到數組的每個項目中。
這就是我所擁有的:
$scope.ProcessExcel = function (data) {
//Read the Excel File data.
var workbook = XLSX.read(data, {
type: 'binary'
});
//Fetch the name of First Sheet.
var firstSheet = workbook.SheetNames[0];
//Read all rows from First Sheet into an JSON array.
var excelRows = XLSX.utils.sheet_to_row_object_array(workbook.Sheets[firstSheet]);
//Display the data from Excel file in Table.
$scope.$apply(function () {
$scope.AgedaItems = excelRows;
});
};
該數組是 $scope.AgendaItems。 它由excel數據填充。
它包含了:
我必須將名為 $scope.meetingId 的變量的值推送到每個記錄,以便在推送后數組內容為:
$scope.AgedaItems: Array(5)
0: {MeetingId: "49490", AgendaItem: "1", LegistarID: "61613", Title: "Title#1", __rowNum__: 1}
1: {MeetingId: "49490", AgendaItem: "2", LegistarID: "60826", Title: "Title#2", __rowNum__: 2}
2: {MeetingId: "49490", AgendaItem: "3", LegistarID: "61168", Title: "Titel#3", __rowNum__: 3}
3: {MeetingId: "49490", AgendaItem: "4", LegistarID: "61612", Title: "Title#4", __rowNum__: 4}
4: {MeetingId: "49490", AgendaItem: "5", LegistarID: "60646", Title: "Title#5", __rowNum__: 5}
有人可以告訴我如何實現這一目標嗎?
謝謝你,埃拉斯莫
如果您實際上只是想在每次迭代中添加 ID“49490”,那么就可以了。
$scope.AgedaItems.forEach(function(item){
item.MeetingId = "49490";
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.