我有以下对象数组:如何在AngularJS中创建一个类似于对象数组对象的空对象?
$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"
}
];
我怎样才能做到这一点?
你确定在阵列将与同一只对象结构体?反正angular不提供清理对象字段的方法,但是你可以简单的写你自己的函数 – Grundy
你为什么要这样做?我知道这不是一个答案,但它似乎违反了我所说的好的编程。有一组东西包含未定义的东西闻起来。 –