0

Here is my link.

Assuming that The testDataArray is received from somewhere server, the html layout is created according to the testDataArray.

What I need to do is: once user typed in something or not, the testDataArray is needed to be converted to the following object, and send back to the server.

And hoping the printed object should looks like:

{
    "Untitled Title 1": "sss",
    "Untitled Title 2":"sss"    
} 

Here is the object, received from the server

$scope.testDataArray = 
    [{
        Question: {
            title: { en: "Untitled Title 1"},
            description: { en: "Untitled description 1"},
            options: {value: {en:""}}
        },Selection: "text"
    },
    {
        Question: {
            title: { en: "Untitled Title 2"},
            description: { en: "Untitled description 2"},
            options: {value: {en:""}}
      },Selection: 'text'
    }];

Could someone help me on that? Thanks a lot!

5
  • This doesn't assign things to your answer array but it does show the value of the text boxes in the section below plnkr.co/edit/OgGQF5?p=preview Commented Mar 27, 2014 at 9:57
  • @BenCr I hope the title-answer object is printed out, format is the same with that in the question Commented Mar 27, 2014 at 10:00
  • okay well binding is quite straight forward and I've shown an example in the plnkr, so is iterating one array and creating a new one, this isn't domyworkforme.com, do some research. Commented Mar 27, 2014 at 10:12
  • @BenCr I dont think it just binding issue! Commented Mar 27, 2014 at 10:16
  • Convert the incoming array to an array, bind to this new array, convert the new array to an object, send it. Simple. The link I put in my original comment shows you binding to arrays. Commented Mar 27, 2014 at 11:40

1 Answer 1

1

Just have a look to this plunkr: http://plnkr.co/edit/R4KUn1bcCEFuaFwix75c?p=preview I used ng-model and pretty much does what you are asking I guess.

// index.html
<div ng-repeat="k in binder">
<input type="text" ng-model="k.val"> 
</div>

// js
$scope.binder = [];
for(var i=0; i<$scope.testDataArray.length;i++){
    var key = $scope.testDataArray[i].Question.title.en;
    var obj = {};
    obj['key'] = key;
    obj['val'] = "";
    $scope.binder.push(obj);
}
Sign up to request clarification or add additional context in comments.

4 Comments

thanks! but it's not I need. Because, the testDataArray is received from server, I dont know how many elements in it, so I cann't create a static array like you provide: $scope.answer = {firstRow:"", secondRow:""};
I did not understand, so you receive that array, and for each of the array element you want to create input texts and with the result of these texts you want to create the object?
hi, thanks for reply! I have re-edited the question, hope it will make sense
Do you have any idea?

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.