I have a recipe model, and a recipe has an ingredientlist collection which stores a bunch of ingredients.
When I add an ingredient to the ingredient list from a form submit, I have to get an 'id' from the server, so I do an ajax request, get the id, and am trying to then add the ingredient to the model.
In my ingredientlist.view, I have
initialize: function(){ this.recipe = this.model; }, get_ingredient: function(ingredient){ var ingredient_id = new MyApp.Models.Ingredient; ingredient.url='/ingredients/?ing='+encodeURIComponent(ingredient_array[i]); ingredient.fetch({ success: function() { this.recipe('add:ingredients', function(ingredient,ingredientlist){ }); }, error: function() { new Error({ message: "adding ingredient" }); } }); }
I didn't include the function which triggers the 'get_ingredient', because it I am getting the ajax fine, so the problem isn't in triggering the 'get_ingredient'.
I get the errorUncaught TypeError: Property 'recipe' of object [object DOMWindow] is not a function
using the existing code.
what is the best way to accomplish something like this?