mgonto / restangular

AngularJS service to handle Rest API Restful Resources properly and easily
MIT License
7.87k stars 840 forks source link

restangular delete item in collection without id #1468

Closed ferdipekcikmaz closed 7 years ago

ferdipekcikmaz commented 7 years ago

{ "_id" : ObjectId("58e35423c575f44bec29d1fd"), "name" : "Ferdi Pekçıkmaz",

"dosya" : [ 
    {
        "dno" : "2017-25",
        "ddate" : "2017-02-31T05:00:00",
        "masraf" : [ 
            {
                "mtutar" : 123.45,
                "mdate" : "2017-01-31T05:00:00"
            }, 
            {
                "mtutar" : 240.75,
                "mdate" : "2017-02-31T05:00:00"
            }
        ],
        "payment" : [ 
            {
                "ptutar" : 2000,
                "pdate" : "2017-01-31T05:00:00"
            }, 
            {
                "ptutar" : 5500,
                "pdate" : "2017-02-31T05:00:00"
            }
        ]
    }, 
    {
        "dno" : "2017-26",
        "ddate" : "2014-12-31T05:00:00",
        "masraf" : [ 
            {
                "mtutar" : 500.15,
                "mdate" : "2014-12-31T05:00:00"
            }, 
            {
                "mtutar" : 740.75,
                "mdate" : "2014-12-31T05:00:00"
            }
        ]
    }, 
    {
        "dno" : "2017-27",
        "ddate" : "2017-03-31T05:00:00",
        "masraf" : [ 
            {
                "mtutar" : 500.5,
                "mdate" : "2014-12-31T05:00:00"
            }, 
            {
                "mtutar" : 340.12,
                "mdate" : "2014-12-31T05:00:00"
            }
        ]
    }
]

}

It is my collection. I want to delete

           {
                "mtutar" : 123.45,
                "mdate" : "2017-01-31T05:00:00"
            }, 

Is it possible? if it is possible how? and i want to insert some item in same list. could you be of assistance about this topic

ferdipekcikmaz commented 7 years ago

I did something like this but I do not know the best solution.

in html

ng-click="deleteMasraf(item, m,$parent.$index)"

in controller

$scope.deleteMasraf = function (item,m,parentIndex) {

    item.dosya[parentIndex].masraf.splice(item.dosya[parentIndex].masraf.indexOf(m),1);
    $scope.customer = item;
    $scope.customer.put();

};