Backbone.js url Model Last Updated : 12 Dec, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report The Backbone.js url Model is a function that is used to get the relative url where the model's resource would be located on the server. If the model is located somewhere else, override this method with the correct logic to get the model. General URLs are of the form of [ Collection.url]/[id]' but we can override this by specifying urlRoot if the Model wants a separate URL. Syntax: model.url() ; Parameters: It does not take any parameters. Example 1: In this example, we will illustrate The Backbone.js url Model. In this example, we get the relative url of the Model which is part of the Collection. Here url would be the General form. HTML <!DOCTYPE html> <html> <head> <title>BackboneJS url Model</title> <script src="https://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"> </script> <script src= "https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.2/underscore-min.js" type="text/javascript"> </script> <script src= "https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.2.2/backbone-min.js" type="text/javascript"> </script> </head> <body> <h1 style="color: green;"> GeeksforGeeks </h1> <h3>BackboneJS url Model</h3> <script type="text/javascript"> var Person = Backbone.Model.extend(); var collection = Backbone.Collection.extend({ model: Person, url: '/book/author' }); // Creating instance of collection; var Coll_Person = new collection(); // Adding model to collection var person = new Person(); Coll_Person.add(person) document.write(`Resource for the Model is reside at : <b> ${person.url()} </b> `); </script> </body> </html> Output: Backbone.js url Model Example 2: In this example, we will override the general form of url with the urlRoot property of the Model and id attribute of the model. HTML <!DOCTYPE html> <html> <head> <title>BackboneJS url Model</title> <script src="https://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"> </script> <script src= "https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.2/underscore-min.js" type="text/javascript"> </script> <script src= "https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.2.2/backbone-min.js" type="text/javascript"> </script> </head> <body> <h1 style="color: green;"> GeeksforGeeks </h1> <h3>BackboneJS url Model</h3> <script type="text/javascript"> var Person = Backbone.Model.extend({ urlRoot: 'https://...com/posts/1/comments' }); // The instance with id attributes var person = new Person(); document.write(`Overriding the url of Model with urlRoot : <b> ${person.url()} </b><br> `); // If we set id attribute person.set('id', 10); document.write(`Overriding the url of Model with urlRoot and id : <b> ${person.url()} </b> `); </script> </body> </html> Output: Backbone.js url model Reference: https://backbonejs.org/#Model-url Comment More infoAdvertise with us Next Article Backbone.js set Model S satyam00so Follow Improve Article Tags : JavaScript Web Technologies Backbone.js backbone.js-Model Similar Reads Backbone.js urlRoot Model The backbone.js urlRoot Model is used when we are using a Model outside the collection. The urlRoot will be used to make the url where the model reside on the server. We can use urlRoot as property and function in both ways. Syntax: model.urlRoot or model.urlRoot() Properties: url: It takes the ur 2 min read Backbone.js parse Model The Backbone.js parse Model is a function that is called whenever a model's data is returned by the server. This function is passed with the response object and returns the model's data. The model has a default implementation of the parse function but we can override this function for flexible usage 2 min read Backbone.js set Model In this article, we will see the Backbone.js set() model. The Backbone.js set() model is used to assign or set the value to the attribute in a model. In other words, this model can be utilized to set the hash of attributes, i.e one or many attributes can be set on the model. The change event will be 2 min read Backbone.js unset Model In this article, we will see the Backbone.js unset model. The Backbone.js unset model is used to unset or remove the value from the attributes in a given model. Syntax: Backbone.Model.unset(attribute); Note: It takes one parameter. attribute: specifies the attribute in a model to be unsettled. Examp 1 min read Backbone.js sync Model Backbone.js sync Model is the function that the model calls every time it attempts to read or save a model to the server. When a model begins a sync with the server, a request event is emitted. If the request completes successfully you'll get a sync event and an error event if not. Syntax: model.syn 2 min read Backbone.js save Model In this article, we will see the Backbone.js save() model. The Backbone.js save() model is used to save the data of the given model by delegating the sync() method. Whenever the backbone is called, every time it reads & saves the model. Syntax: Backbone.Model.save(attributes, [options]);Paramete 2 min read Like