<!DOCTYPE HTML><HTML><Head> <MetaCharSet= "Utf-8"> <title></title> <Linkrel= "stylesheet"href=".. /.. /app-min.css "></Head><Body> <Scriptsrc=".. /.. /jquery/jquery-1.10.2.js "></Script> <Scriptsrc=".. /underscore.js "></Script> <Scriptsrc=".. /backbone.js "></Script> <Script> varMans=Backbone.Model.extend ({URL:'/man/', Initialize:function() {Console.log ('Initialize') //binding listening at initialization This. Bind ('Change:name', function() { varname= This. Get ('name') Console.log ('You changed name to' +name)}) This. Bind ('Invalid', function(model, error) {Console.log (Error)}) This. Bind ('Error', function(model, error) {Console.log (Error)})}, defaults: { Name:'name', Age:' Age'}, Validate:function(attributes) {if(Attributes.name== "') { return 'name cannot be empty'}}, Aboutme:function() { return 'wo Jiao' + This. Get ('name') } }) varMans= NewMan Console.log (Man.get ('name') ) Man.set ({name:"'}) Console.log (Man.get ('name')) Console.log (Man.aboutme () )//calling the Save method will post all properties of the object to the server side //The fetch method is called and a GET request is sent to the server side //accept data and send data in JSON formatMan.save ()//trigger validation when save. Pop-up error notification based on validation rules //Man.fetch () //man.fetch ({url: '/man/'})man.fetch ({URL:'/man/', Success:function(model, response) {//the model is the obtained dataConsole.log (Model.get ('name') }, Error:function() {Console.log ('Error') } }) //after you set up UrlRoot, when you send a put and delete request, the URL address of the request is:/baseurl/[model.id] </Script> <articleclass= "Content"> <Pre>var man = Backbone.Model.extend ({url: '/man/', initialize:function () {console.log (' Initialize ')// When initializing the binding listener this.bind (' Change:name ', function () {var name = This.get (' name ') Console.log (' You c Hanged name to ' + name} ') This.bind (' Invalid ', function (model, error) {Console.log (Error) }) This.bind (' Error ', function (model, error) {Console.log (Error)})}, defaults: { Name: ' Name ', Age: ' Age '}, validate:function (attributes) {if (Attributes.name = = ') { Return ' name cannot be empty '}}, Aboutme:function () {return ' wo jiao ' + this.get (' name ')}}) var man = new Mans Console.log (Man.get (' name ')) Man.set ({name: '}) Console.log (Man.get (' name ')) Console.log (Man.ab Outme ())///Call the Save method when all properties of the Post object to the server side//Call fetch method is to send the GET request to server side///Accept data and send data both as JSON format man.save ()//SA ve when triggering validation. Pop-up error notification based on validation rules Man.fetch ()//man.fetch ({url: '/man/'}) man.fetch ({url: '/man/', success:function (model, response) { Model for acquired data Console.log (Model.get (' name ')}, Error:function () {console.log (' Error ')}})// After you set up UrlRoot, when you send a put and delete request, the URL address of the request is:/baseurl/[model.id]</Pre> </article></Body></HTML>
-_-# "Backbone" Model