after having finished the couchapp tutorial, the last step from there has to be done: saving the created pizza.
For this I have created a JS function "saveToppings", which is executed (as the firebug console shows) but fails uppon saving my JSON document with the message:
The document could not be saved: Document must be a JSON object.
So I understand, my doc is no JSON doc, but I don't know how to do this properly.
Here is the code of the "saveToppings" function:
function(e){
var json_toppings = JSON.stringify($$(this).toppings);
var merged_toppings = "{ \"type\":\"topping\", \"contents\":" + json_toppings + "}";
$.log('json_toppings: '+ json_toppings.toString());
$.log('merged_toppings: '+ merged_toppings.toString());
$$(this).app.db.saveDoc(merged_toppings, {
success : function() {
alert("Doc saved successfully.");
}
});
}
...and the debug from the console:
json_toppings: [{"top":"tomatoes"},{"top":"bacon"},{"top":"cheese"}]
merged_toppings: { "type":"topping", "contents":[{"top":"tomatoes"},{"top":"bacon"},{"top":"cheese"}]}
So, just figured it out.
I extended my debugging to get the object types from my "toppings" objects with
...and they are Strings. So I am now using jquery to create an JSON object:
...and it's working. The complete code here: