在POST到API之前更改值数组angularJS

时间:2016-11-17 18:11:59

标签: javascript angularjs arrays

我有一个数组:

[{"IDAlokasiEmiten":154,"IDOrganization":12,"NamaOrganization":null,"CodeEmiten":"ANTM","NameEmiten":"AAneka Tambang (Persero) Tbk"},{"IDAlokasiEmiten":0,"IDOrganization":null,"NamaOrganization":null,"CodeEmiten":"ADHI","NameEmiten":"Adhi Karya (Persero) Tbk"}]

如何在发布到API之前更改某些值?

我希望POST到API:

[{"IDAlokasiEmiten":0,"IDOrganization":12,"NamaOrganization":null,"CodeEmiten":"ANTM","NameEmiten":"AAneka Tambang (Persero) Tbk"},{"IDAlokasiEmiten":0,"IDOrganization":12,"NamaOrganization":null,"CodeEmiten":"ADHI","NameEmiten":"Adhi Karya (Persero) Tbk"}]

这是我的AngularJS:

// GET Detail Alokasi Emiten
    $scope.emit.detailDaftarEmiten = [];
    $scope.addItemAlokasi = function () {
        $scope.emit.detailDaftarEmiten.push({
            IDAlokasiEmiten: 0,
            IDOrganization: 12,
            NamaOrganization: '',
            CodeEmiten: $scope.emit.detailDaftarEmiten.CodeEmiten,
            NameEmiten: $scope.emit.detailDaftarEmiten.NameEmiten
        });
        $scope.emit.detailDaftarEmiten.IDAlokasiEmiten = '';
        $scope.emit.detailDaftarEmiten.IDOrganization = '';
        $scope.emit.detailDaftarEmiten.NamaOrganization = '';
        $scope.emit.detailDaftarEmiten.CodeEmiten = '';
        $scope.emit.detailDaftarEmiten.NameEmiten = ''
    };
    $scope.resetForm = function () {
        $scope.emit.detailDaftarEmiten.IDAlokasiEmiten = ''; 
        $scope.emit.detailDaftarEmiten.IDOrganization = '';
        $scope.emit.detailDaftarEmiten.NamaOrganization = '';
        $scope.emit.detailDaftarEmiten.CodeEmiten = '';
        $scope.emit.detailDaftarEmiten.NameEmiten = ''
    };
    $scope.deleteItem = function (index) {
        $scope.emit.detailDaftarEmiten.splice(index, 1);
    };
    $scope.getTotalItems = function () {
        return $scope.detailDaftarEmiten.length;
    };

但它不起作用:(

我想为(IDAlokasiEmiten=0IDOrganization=12)设置所有值数组。

1 个答案:

答案 0 :(得分:0)

当您提出发布请求时,您将数组数据(您想要的数据)保留在发布请求的正文中。例如: http.post(url,{(您的数据(按键排序对)}) 这将返回您将访问结果的承诺中的承诺。 。希望它有用