mardi 17 février 2015

Push data submitted through form to JSON array in Ember JS

I'm creating an app that tracks items you eat all day. Part of the process involves adding detailed information about each item you eat, including calories, carbs, fat, etc ... (think MyFitnessPal)


Currently the app allows the user to add new items they've eaten. So the user adds the name through an input and a page gets created for that item. The page that is created has a form where the user can add in the detailed information mentioned above. This is where I'm stuck.


I want the user to be able to type in information and submit it through the form and have it be added to the JSON array.


So what starts out as:



var itemLibrary = [
{
'name' : 'bread'
},
{
'name' : 'milk'
}
];


Would then have detailed information:



var itemLibrary = [
{
'name' : 'bread',
'quantity' : '1 loaf',
'description' : 'this is whole wheat bread i bought at walmart'
},
{
'name' : 'milk'
}
];


In the end there would be a page where the user could view the details they entered previously. So I was thinking I'd use some sort of JSON parse method to do that.


I thought some sort of serialization would need to take place for the form submission to add the data to the JSON array, but I'm not sure, and I can't find much through the Ember documentation or articles online.


Thanks.





Aucun commentaire:

Enregistrer un commentaire