I am using JSON to send Ajax data. I get a comma mobile number from the input text box. And I convert it to a javascript array.
Below is my code:
var myarray = {}; myarray = this.model.get('mobileno').split(',');
Result: myarray: ["123", "4567"];
I am going to set the same value for my model as below:
this.model.set('mobileno',JSON.stringify(myarray ));
Then the value becomes as follows:
console.log(this.model.get('mobileno'));
Result: mobileno: "[" 123 "," 4567 "]"
So my model became this.model.toJSON();
Result: object {mobileno: "[" 123 "," 4567 "]}
So far, everything is correct. after that I need to install this model on another model, and running stringfy will give me the following:
anotherModel.set('data', this.model);
"data": {"MobileNo": "[\" 123 \ "\" 456 \ "]"}
But I need "data": {"mobileno": ["123", "456"]}
Your help will be appreciated.