Learn some doubts in the backbone

Source: Internet
Author: User

What is the difference between 1,model Id,idattribute and CID?

A: Both CID and ID are unique identifiers of model, and either can be used to return a model from collection.

The CID stores the client unique identity that Backbone.js has assigned to the model, and in some cases (such as new data), your object has not yet been stored in the database, and the model does not have a unique identity, but the client generates a CID for it, at this point, at the client's point of view, this m There is no difference between Odel and other similar model, so that the front-end code can easily handle this type of model without regard to special cases.

Ideally, we hope that the server uses the server-side identity, the client uses the client's identity

However, if the data needs to interact with the server, it is necessary to establish a correspondence between the two-party data, which is the function of the ID. The ID stores the unique identity of the data on the server, such as the server's primary key called "id", which can be used to update the data on the server model when the client model is updated.

However, our server model's primary key is named by the server developer, not necessarily called "id" (good annoying), then, the client should be able to specify the model ID corresponding to the server model of which the primary key, then the birth of Idattribute is taken for granted.

Three combination, let the front-end code more convenient, clear, have to say, this design is very ingenious.


Learn some doubts in the backbone

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.