I have a Backbone collection from serer with attributes id
and name
.
I get new name from input.
var a = $('#newFoodtype').val();
And create new model and adding to collection;
var b = new app.Foodtype({ "name" :a });
this.collection.add(b);
The new model doesn't have an id
attribute. I know all model have a id
.
How to generate a unique id and set this to new models.
I will delete some models in collection, therefore collection.length
is good idea. I will send this to the server. One solution is to send only the "name"
and generate the "id"
on the server during the insert to the DB.
Is it possible to generate this from the client side?