我有以下对象数组:
$scope.users = [
{
ID: "1",
Name: "Hege",
Username: "Pege",
Password: "hp",
},
{
ID: "2",
Name: "Peter",
Username: "Pan",
Password: "pp"
}
];
我需要创建一个类似的对象,其中所有值都为空,如下所示:
$scope.newUser = {
ID: "",
Name: "",
Username: "",
Password: ""
}
这样我就可以将它推送到相同的数组中($scope.users.push($scope.newUser);
),让它看起来像这样:
$scope.users = [
{
ID: "1",
Name: "Hege",
Username: "Pege",
Password: "hp"
},
{
ID: "2",
Name: "Peter",
Username: "Pan",
Password: "pp"
},
{
ID: "",
Name: "",
Username: "",
Password: ""
}
];
然而,数组$scope.users
并不总是具有相同对象的数组。我需要使其能够在我更改数组为其他内容时正常工作,例如像这样:
$scope.users = [
{
SID: "pepe",
Name: "Peter",
School: "Primary School"
},
{
SID: "hepe",
Name: "Hege",
School: "Junior School"
}
];
我该如何做到这一点?