zoukankan      html  css  js  c++  java
  • ExtJs Ext.data.Model 学习笔记

    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!');
        }
    });

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

     : 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.() 拿不到。用过上述的ID自动成功策略可以解决此问题

  • 相关阅读:
    Echarts图表 相关技术点
    Jquery off() on() data()
    Js 正则表达式
    Java jar项目获取配置文件的项
    Java String.split 的坑,会忽略空值
    C# 工作流 状态机 门控制
    二维码SDK,高效率,高识别率,甩zxing,zbar几条街
    C#文本转语音,可导出在本地mp3或者wav文件
    api接口签名验证(MD5)
    C# 站点IP访问频率限制 针对单个站点的实现方法
  • 原文地址:https://www.cnblogs.com/daxin/p/3205705.html
Copyright © 2011-2022 走看看