-1

i'm using angular js for creating the json, but when i tried to make a json as shown below

$scope.newcolumns =[{"File 1":"file1.png"},{"File 1":"file2.png"}]

i'm getting missing : after property id

my code is as given below

 $scope.newcolumns = [];
    angular.forEach( $scope.datas, function(data){
            $scope.newcolumns.push({data.id : data.value});
    });

can anyone please tell me some solution for this

2
  • What is the content of datas? And be careful withe the wording, your not creating json, but straight forward Javascript variables Commented Mar 10, 2014 at 8:46
  • Could you remove space from File 1 and try again Commented Mar 10, 2014 at 8:47

2 Answers 2

2

I think you need to do something like this,

var obj={};
obj[data.id]= data.value;
$scope.newcolumns.push(obj);

{data.id : data.value} is not a valied syntax data.id should be some name to a property it cannot be a variable. If you need to have variable field names then you need to do like above.

Sign up to request clarification or add additional context in comments.

Comments

-1

angular.foreach(data, function (e) { $scope.phones.push({ "File1 ": e.File1, "File2": e.File2}); }); Sorry, I can only do this for you

1 Comment

Problem solved on top, answer not clear enough fix and I will remove downvote

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.