-_-#【Backbone】Model

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="../../app-min.css">
</head>
<body>
    <script src="../../jquery/jquery-1.10.2.js"></script>
    <script src="../underscore.js"></script>
    <script src="../backbone.js"></script>
    <script>
        var Man = Backbone.Model.extend({
            url: ‘/man/‘,
            initialize: function() {
                console.log(‘initialize‘)
                // 初始化时绑定监听
                this.bind(‘change:name‘, function() {
                    var name = 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不能为空‘
                }
            },
            aboutMe: function() {
                return ‘wo jiao ‘ + this.get(‘name‘)
            }
        })

        var man = new Man
        console.log(man.get(‘name‘))
        man.set({name: ‘‘})
        console.log(man.get(‘name‘))
        console.log(man.aboutMe())
        // 调用save方法时会post对象的所有属性到server端
        // 调用fetch方法是又会发送get请求到server端
        // 接受数据和发送数据均为json格式
        man.save() // save时触发验证。根据验证规则,弹出错误提示

        //man.fetch()
        //man.fetch({url:‘/man/‘})
        man.fetch({
            url: ‘/man/‘,
            success: function(model, response) {
                // model 为获取到的数据
                console.log(model.get(‘name‘))
            },
            error: function() {
                console.log(‘error‘)
            }
        })
        // 你设置了urlRoot之后,你发送PUT和DELETE请求的时候,其请求的url地址就是:/baseurl/[model.id]
    </script>
    <article class="content">
        <pre>var Man = Backbone.Model.extend({
    url: ‘/man/‘,
    initialize: function() {
        console.log(‘initialize‘)
        // 初始化时绑定监听
        this.bind(‘change:name‘, function() {
            var name = 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不能为空‘
        }
    },
    aboutMe: function() {
        return ‘wo jiao ‘ + this.get(‘name‘)
    }
    })

    var man = new Man
    console.log(man.get(‘name‘))
    man.set({name: ‘‘})
    console.log(man.get(‘name‘))
    console.log(man.aboutMe())
    // 调用save方法时会post对象的所有属性到server端
    // 调用fetch方法是又会发送get请求到server端
    // 接受数据和发送数据均为json格式
    man.save() // save时触发验证。根据验证规则,弹出错误提示

    //man.fetch()
    //man.fetch({url:‘/man/‘})
    man.fetch({
    url: ‘/man/‘,
    success: function(model, response) {
        // model 为获取到的数据
        console.log(model.get(‘name‘))
    },
    error: function() {
        console.log(‘error‘)
    }
})
// 你设置了urlRoot之后,你发送PUT和DELETE请求的时候,其请求的url地址就是:/baseurl/[model.id]</pre>
    </article>
</body>
</html>
时间: 2024-08-01 00:05:24

-_-#【Backbone】Model的相关文章

-_-#【Backbone】Collection

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <link rel="stylesheet" href="../../app-min.css"> </head> <body> <script src="../../jquery/jque

-_-#【Backbone】View

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <link rel="stylesheet" href="../../app-min.css"> <script src="../../jquery/jquery-1.10.2.js"></

【Backbone】简介

1.Model 2.Collection 3.View 4.Router 5.History 6.Events http://addyosmani.github.io/backbone-fundamentals/ [Backbone]简介,布布扣,bubuko.com

接口和抽象类:Interface、abstract _【转】

一.接口 接口是C#中很常见的工具,概念什么的就不说了,这里讲几个值得注意的小地方: 1.接口内部只能有函数.属性和事件的声明: interface IParent { void Show(); string Type { get; set; } event AddChildren Add; } 在接口中声明的成员都不需要访问修饰符(public,private等),因为接口成员的权限默认都是public,另外值得注意的是接口中之所以能够声明事件是因为事件就是委托的特殊属性. 接口不能是静态的,

【QuotationTool】Model的实现(二),形成价格明细清单.md

项目链接:https://gitee.com/xyjtysk/quotationTools 在[QuotationTool]Model的实现(一),获得Excel路径以及Excel输出格式里面我们已经获得了Excel的路径,已经规定好了输出和输出有哪些列,下面就可以开始正式转换了. 预处理 由Controller进行调度 首先自然是读取Excel,我们在Controller里面调用XlrdTool中的getAssociativeArray lists = XlrdTool().getAssoci

【Django】--Model字段

所有字段 AutoField(Field) --int自增列,必须填入参数primary_key=True BigAutoField(AutoField) --bigint自增列,必须填入参数primary_key=True 注意:当model中没有自增列,则自动会创建一个列名为id的列 from django.db import models class UserInfo(models.Model): #自动创建一个列名为id的且为自增的整数列 username = models.CharFi

转载_【译】Android Studio使用技巧系列之快捷键01

转自:[译]Android Studio使用技巧系列之快捷键01 打开类/文件/符号 打开类 1 2 mac: cmd + o win/linux: ctrl + n 假设你要打开快速切换到如MainActivity.java的类,可以使用该快捷键然后输入MainA… 打开文件 1 2 mac: cmd + shift + o win/linux: ctrl + shift + n 和打开类相似,但是该快捷键可以打开工程目录下的任意文件.这可以快速帮你打开如AndroidManifest.xml

Python 系统学习梳理_【All】

Python学习 1. Python学习---Python安装与基础1205 2. Python学习---PyCharm的使用学习 3. Python学习---Python数据类型1206 4. Python学习---range/for/break/continue简单使用 5. Python学习---列表/元组/字典/字符串/set集合/深浅拷贝1207[all] 6. Python学习---文件操作的学习1208 7. Python学习---函数的学习1209[all] 8. Python学

【QuotationTool】Model的实现(一),获得Excel路径以及Excel输出格式

项目链接:https://gitee.com/xyjtysk/quotationTools 在[QuotationTool的代码实现]主要数据结构.md中,我们介绍了如何针对的本项目的主要数据结构是什么,也就是把Excel表格里面的数据读出来,放到什么样的结构里面方便后续的处理. 下面我们接着介绍如何实现明细清单页. 要实现完成的流程,我们首先得获得Excel所在的完整路径+文件名,以及对输出的表格有那些列进行限定. 获得输入Excel路径 outputfileModelClass.py就是用来