The Backbone.js cid Model is a unique identifier to the model. It is automatically assigned to the model when they are first created. Cid is useful when we did not assign any unique identifier to the model. The cid stands for client id.
Syntax:
Backbone.model.cid
Parameters: It does not accept any parameters.
Using the CDN Link: A content delivery network is a network that serves the file to the user. Here is CDN link for Backbone.js.
<script src= “https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.2.2/backbone-min.js” type=”text/javascript”> </script>
Example: In this example, we will see that every instance of the model is assigned with a unique cid automatically.
HTML
<!DOCTYPE html> < html > < head > < title >BackboneJS Model cid</ title > type = "text/javascript" > </ script > < script src = type = "text/javascript" > </ script > < script src = type = "text/javascript" > </ script > </ head > < body > < h1 style = "color: green;" > neveropen </ h1 > < h3 >BackboneJS Model cid</ h3 > < script type = "text/javascript" > var Geek = Backbone.Model.extend(); var geek = new Geek(); var geek2 = new Geek(); var geek3 = new Geek(); var geek4 = new Geek(); document.write("Cid of first instance of Geek : " + geek.cid + '< br >'); document.write("Cid of second instance of Geek : " + geek2.cid + '< br >'); document.write("Cid of third instance of Geek : " + geek3.cid + '< br >'); document.write("Cid of fourth instance of Geek : " + geek4.cid + '< br >'); </ script > </ body > </ html > |
Output:
Example 2: In this example, we will see that as another property of the object we can access cid and change it with our desired unique identifier.
HTML
<!DOCTYPE html> < html > < head > < title >BackboneJS Model cid</ title > type = "text/javascript" > </ script > < script src = type = "text/javascript" > </ script > < script src = type = "text/javascript" > </ script > </ head > < body > < h1 style = "color: green;" > neveropen </ h1 > < h3 >BackboneJS Model cid</ h3 > < script type = "text/javascript" > var Geek = Backbone.Model.extend(); var geek = new Geek(); var cody = new Geek(); document.write("Cid of geek Before change : " + geek.cid + "< br >"); document.write("Cid of cody Before change : " + cody.cid + "< br >"); // Changing Cid of model geek.cid = 1001; cody.cid = 1002; document.write("Cid of geek after change : " + geek.cid + "< br >"); document.write("Cid of cody after change : " + cody.cid + "< br >"); </ script > </ body > </ html > |
Output:
Reference: https://backbonejs.org/#Model-cid