在angularJS中创建并使用另一个对象

时间:2020-12-01 23:09:24

I have a variable/object called Student. it's attributes are: name,surname,address.I want it to have one more attribute-"classroom", All I want is to create a new object classroom,which attributes will be "class_number" and "class_type"... So I want:

我有一个名为Student的变量/对象。它的属性是:姓名,地址。我希望它有一个属性 - “教室”,我想要的是创建一个新的对象教室,其属性将是“class_number”和“class_type”......所以我想:

 var student : [{
    name: "Jacob"
    surname:"Black"
    adress:"Baltimore Street N2",
    classroom: // I dont know how to write this
    }];

2 个解决方案

#1


0  

var student : [{
    name: "Jacob"
    surname:"Black"
    adress:"Baltimore Street N2",
    classroom: {
        "class_number":"101",
        "class_type":"programming"
    }
}];

#2


0  

Simply you can do as follows:

您只需按以下步骤操作即可:

var classroom = {
      class_number : xxx;
      class_type : 'xxx';
    }

student.classroom = classroom;

#1


0  

var student : [{
    name: "Jacob"
    surname:"Black"
    adress:"Baltimore Street N2",
    classroom: {
        "class_number":"101",
        "class_type":"programming"
    }
}];

#2


0  

Simply you can do as follows:

您只需按以下步骤操作即可:

var classroom = {
      class_number : xxx;
      class_type : 'xxx';
    }

student.classroom = classroom;