cid is updated after .create() (AJAX)

13 views
Skip to first unread message

sebastia...@gmail.com

unread,
Nov 19, 2015, 7:40:19 PM11/19/15
to Spine
Hi!

I'm facing a problem right now. Maybe I don't understand the whole underlying concept, but I hope you can help me though.

I'm trying to create a new record using the .create method

User.create("ec-name": "Name", "ec-mail": "Emailaddress", "ec-phone": "Phone number", "reference": "Reference")

I bound the "create" and "change" events of the Model to methods called @addElement and @changeElement.
@addElement appends an html element (templated using Handlebars) in a table giving that html element an HTML-ID value of the current cid of the record.
@changeElement tries to recognize, whether the current "change" is an ID change or a change of some other attribute of the record. If it is an ID change the method changes the ID of the html element to the server-side ID.

changeElement: (element) =>
 
unless $('#user-'+element.id).length
 console
.log $('#user-'+element.id).length
 $
('#user-'+element.cid).attr("id",element.id);
 
else
 $
('#user-'+element.id).replaceWith(@template(element))


The problem: At first the cid of the element is "c-0". But the first "change" event "sends" a record with a cid "c-1" and a server provided value in "id". So there is absolutely no way for me to recognize that my just created record with a cid/id value of "c-0" just received a server provided ID as the cid values don't match. Is this intended behaviour or am I getting almost everything wrong? Then I'd be happy to learn a best practice....

Best regards,
Sebastian.
Reply all
Reply to author
Forward
0 new messages