Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Simon Dingley 1474 posts 3431 karma points c-trib
    Nov 27, 2015 @ 08:22
    Simon Dingley
    0

    Custom Grid Editor Model change without loss of data

    I have a problem in that I have a Grid Editor that has data added and I need to change the model without losing the data.

    Currently the value of $scope.control.value is an array of objects e.g.

    $scope.control.value[0]
    $scope.control.value[1]
    $scope.control.value[2]
    $scope.control.value[...]
    

    ...however I need to move all of the objects into a new a property so that my model is more like:

    $scope.control.value.a_new_object
    $scope.control.value.datapoints[0]
    $scope.control.value.datapoints[1]
    $scope.control.value.datapoints[2]
    $scope.control.value.datapoints[...]
    

    I've tried the following:

    if (!$scope.control.value.datapoints) {
        $scope.control.value.datapoints = angular.copy($scope.control.value);
        for(var i = $scope.control.value.length -1; i >= 0 ; i--){
            $scope.control.value.splice(i, 1);
        }
    }
    

    Which when stepping through appears to have the expected result however on publishing the page and reloading all data is lost and the new array is empty?

Please Sign in or register to post replies

Write your reply to:

Draft