Backbone.js - id vs idAttribute vs cid

后端 未结 4 1910
一个人的身影
一个人的身影 2020-12-24 00:56

I\'ve been studying Backbone.js for a few weeks, and I feel comfortable using views with models, routers, and collections.

I still have some big gaps:

4条回答
  •  生来不讨喜
    2020-12-24 01:37

    id - id that might be manually set when the model is created, or is populated when model has been saved on the server (see "idAttribute" at the bottom to see the connection). This is the id that is sent to the server when model is loaded or updated from server e.g., for a model Person this call will be made if id is 123, "/person/123"

    cid - unique id set my backbone model for internal use

    idAttribute - this decides which property will act as the unique id (default is "id") when the model has been saved on the server e.g., a model's unique key on the server might be defined by "personId", so when fetch is called model will map the server response from "personId" to id in the backbone model.

提交回复
热议问题