I’m using Backbone and Parse to build a survey website. I imitated the Todo list example to add a question to the page. As in the todo list example, I have “createOnEnter” and “addOne”. Getting the id is important to me because I need to set the id of the question the same as its id in Parse.
addOne: function(question) {
alert(question.get("content"));
alert(question.id);
var view = new QuestionView({model: question});
this.$("#questions").append(view.render().el);
},
createOnEnter: function(e) {
if (e.keyCode != 13) {
return;
}
this.survey.create({
content: $("#new-question").val(),
type: $("#choose-type").val(),
order: this.survey.nextOrder(),
user: Parse.User.current(),
ACL: new Parse.ACL(Parse.User.current())
}, {wait: true});
$("#new-question").val('');
}
So alert(question.get(“content”)) will indeed gave me the expected content but alert(question.id) shows undefined. However I believe each entry saved to Parse will get a unique id so I couldn’t understand why question.id is undefined. Even worse, alert(question.get(“cid”)) is also undefined…..This is really confusing to me.
Thanks a lot!!!
idsare given by the server (when youfetchand the server return anidfields). It could also get added if when you create your model you manually add anidfield – but the point is that this isn’t done automatically.idis the unique identifier of a resource on the server.As you’re creating question on the frontend, you’ll need to use the unique id Backbone create who’s called
cid. http://backbonejs.org/#Model-cid