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. C#编写的 8种初级+高级排序方法(转)

    摘自:http://blog.csdn.net/mevin/article/details/6714520 程序代码: view plaincopy to clipboard using System ...

  2. MyEclipse 8.6插件下载

    (源自网络:http://hi.baidu.com/%D4%B5%BA%A3%C7%E9%C9%EE/blog/item/ad86323d1e80a5e33d6d97c6.html  和 http:/ ...

  3. jsp中Undefined type: xxxx...

    在测试jsp的动作元素<jsp:useBean >时,写了一个计数器的栗子: JavaBean: package com.pers.count; /** * @author liangya ...

  4. HDUOJ---1863畅通工程

    畅通工程 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  5. 几道比较难的SQL题

    上条记录和下一条记录 在展示博客文章时,在文章底部需要展示上一篇文章和下一篇文章,文章的排序当然是按照时间排序的. 选定下一条时可以用limit 1来实现,选取上一条时可以倒序limit 1实现 (S ...

  6. APK 本地化和去广告

    APK 本地化       说起APK的汉化,目前大部分教程都是让用Hex Workshop或者Android ResEdit来做.但是实际操作后,就会发现: 1.Hex Workshop操作繁琐,经 ...

  7. 解决修改计算机名后tfs连接不上的错误

    1,用vs 自带的工具命令 tf workspaces 查看集合 2,执行命令: >tf workspaces /collection:https://aaaa.visualstudio.com ...

  8. Quartz.net官方开发指南[转]

    http://www.cnblogs.com/shanyou/category/102991.html

  9. memset(&a, 0, sizeof(struct customer))函数

    memset(&a, 0, sizeof(struct customer))函数定义在memory.h中,用于给指定的内存区域赋值,在该语句中,&a指定待赋值的内存首地址,0是要赋的值 ...

  10. MySQL数据库查询优化建议

    1. 对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2. 应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使 ...