我尝试使用push()在数组中添加值数组,但我不知道如何添加它

时间:2016-05-31 12:27:01

标签: javascript arrays angularjs

这个mycode,我尝试在company1的工作人员中重视,但它创建了一个新的数组列表。有人能帮助我吗?

在我添加人员的名称和ID后,数组将如下所示

  

[{companyName:" company1&#34 ;, companyAddress:"公司地址",员工:   [{name:" men",id:" 123"},{name:" boy",id:" 1343"},{名:"约翰",ID:   " 145"}]}]

<div ng-controller="MyCtrl">
    <input type="text" ng-model="nameStaff" />
    <input type="text" ng-model="idStaff" />
    <button ng-click=addDetail()>add</button>
    {{form}}
</div>

var myApp = angular.module('myApp', []);

function MyCtrl($scope) {
    $scope.form = [{ companyName: "company1", companyAddress: "company address", staff: [{ name: "men", id: "123" }] }];
    $scope.addDetail = function() {
        $scope.form.push({ staff: [{ name: $scope.nameStaff, id: $scope.idStaff }] });
    }
}

1 个答案:

答案 0 :(得分:1)

您正在推进[y1,fs1] = audioread(myfile1); [y2,fs2] = audioread(myfile2); ,但您希望继续form中第一个对象的staff

form