-_-# "Backbone" Model

Source: Internet
Author: User

<!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

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.