Using a Proxy

Ext.define('User', {
extend: 'Ext.data.Model',
fields: ['id', 'name', 'email'], proxy: {
type: 'rest',
url : '/users'
}
});

当在Model中定义了一个Proxy以后就可以使用 save,update,load,destroy这4个方法 进行增删改查操作

var user = Ext.create('User', {name: 'Ed Spencer', email: 'ed@sencha.com'});

user.save(); //POST /users
//get a reference to the User model class
var User = Ext.ModelManager.getModel('User'); //Uses the configured RestProxy to make a GET request to /users/123
User.load(123, {
success: function(user) {
console.log(user.getId()); //logs 123
}
});
//the user Model we loaded in the last snippet:
user.set('name', 'Edward Spencer'); //tells the Proxy to save the Model. In this case it will perform a PUT request to /users/123 as this Model already has an id
user.save({
success: function() {
console.log('The User was updated');
}
}); //tells the Proxy to destroy the Model. Performs a DELETE request to /users/123
user.destroy({
success: function() {
console.log('The User was destroyed!');
}
});

commit( [silent], [modifiedFieldNames] ) 该方法用于提交Model的修改.会通知Store,在gridPanel中 model修改以后会有红色标记,该方法会提交修改.

phantom: Boolean 该属性标记该 Model实体是否是 新的 如果没有ID 这为true, 否则为false. 如果在前台gridPanel中手动加入Model 那么有又ID的话 可以手动设置为false

Ext.define('MyApp.data.MyModel', {
extend: 'Ext.data.Model',
requires: ['Ext.data.UuidGenerator'],
idgen: 'uuid',
...
});

可以给Model设置ID生成策略 这样就可以New出来的Model在通过Store.sync();就可以调用Insert方法了。

不然有ID的Model Store会认为不是新数据 那么通过Store.getModifiedRecords() 拿不到。用过上述的ID自动成功策略可以解决此问题

ExtJs Ext.data.Model 学习笔记的更多相关文章

  1. [ExtJs] ExtJs4.2 数据模型Ext.data.Model学习

    Model代表应用程序管理的一些对象.例如,我们可能会为 我们想在系统中建模的现实世界中的一些物体像使用者.产品和汽车等定义一个Model.这些Model在 Ext.ModelManager中注册,被 ...

  2. EXtJS Ext.data.Model

    (一).首先我们介绍一下Model类中比较常用的几个属性,如果我们想构建一个Model类,最主要的属性就是(Fields)属性,这个属性接受一个数组.用来设置Model中所包含的字段.定义的格式如下: ...

  3. ExtJS笔记 Ext.data.Model

    A Model represents some object that your application manages. For example, one might define a Model ...

  4. ExtJS教程(5)---Ext.data.Model之高级应用

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/jaune161/article/details/37391399 1.Model的数据验证 这里借助 ...

  5. ExtJS 4.2.1学习笔记(一)——MVC架构与布局

    1       ExtJS入门 1.1     支持所有主流浏览器 调试推荐:chrome.Safari.Firefox 1.2     推荐目录结构 - appname (包含所有程序代码,是根目录 ...

  6. ExtJs Ext.data.Store 处理

    var storeCpye = new Ext.data.GroupingStore({ proxy : new Ext.data.HttpProxy({ url : 'cxgl_cpye.app?d ...

  7. [Spring Data Repositories]学习笔记--使用现有的repository

    以下内容是在学习Spring-Data-mongoDB中的Spring Data Repositories时做的一些笔记.备忘! 感觉学习还是看官方的资料比较透彻一些. Spring Data Rep ...

  8. ExtJS 4.2.1学习笔记(二)——主题theme

    1                 UI组件基础 学习ExtJs就是学习组件的使用.ExtJs4对框架进行了重构,其中最重要的就是形成了一个结构及层次分明的组件体系,由这些组件形成了Ext的控件. E ...

  9. Core Data Stack学习笔记

    Entity Entities 实体->数据表一个实体可以表示一个数据模型 1> 通过图形化界面可以建立一个模型关系图,可以指定一对多,多对一,多对多的数据关系 -在数据库开发中,少用多对 ...

随机推荐

  1. HDUOJ-------Naive and Silly Muggles

    Naive and Silly Muggles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/ ...

  2. 【LeetCode】39. Combination Sum (2 solutions)

    Combination Sum Given a set of candidate numbers (C) and a target number (T), find all unique combin ...

  3. php计算经纬度间的距离

    <?php //根据经纬度计算距离 function getdistance($lng1,$lat1,$lng2,$lat2) { //将角度转为狐度 $radLat1=deg2rad($lat ...

  4. jsp里面实现asp.net的Global文件内容。

    Global.java文件: import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import ...

  5. Python rpartition() 方法

    描述 Python rpartition() 方法用来根据指定的分隔符将字符串进行分割. 如果字符串包含指定的分隔符,则返回一个3元的元组,第一个为分隔符前面的子字符串,第二个为分隔符本身,第三个为分 ...

  6. 群智能优化算法-测试函数matlab源码

    群智能优化算法测试函数matlab源代码 global M; creatematrix(2); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %画ackley图. %%%% ...

  7. windows server 2012 r2 8080外网访问端口发布设置

    windowser server 2012 r2 8080外网访问端口发布设置,在配置服务器时候,8080端口作为默认的web访问的端口,那么如何配置呢如下步骤: 工具/原料 windowser se ...

  8. AAA含义图解

    来源: <FreeRADIUS Beginner's Guide> 这本书 1,认证 2,授权 3,审计

  9. SQL Server 备份数据库到指定路径,任务实现

    --Description:备份指定数据到指定路径,第一次完整备份.每月1号完整备份.每周一完整,每天增量备份--====================================ALTER p ...

  10. pgrep -f 和pkill -f

    pgrep -f abc 匹配出含abc的进程 并输出进程的pid pkill -f abc 杀掉含abc的所有进程