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自动成功策略可以解决此问题

  • 相关阅读:
    第 15 章 标签页和工具提示插件
    第 14 章 下拉菜单和滚动监听插件
    第 13 章 模态框插件
    第 12 章 列表组面板和嵌入组件
    第 11 章 进度条媒体对象和 Well 组件
    第 10 章 巨幕页头缩略图和警告框组件
    第 9 章 路径分页标签和徽章组件
    lock()与lockInterruptibly()的区别
    MySQL中Innodb的聚簇索引和非聚簇索引
    MySQL使用可重复读作为默认隔离级别的原因
  • 原文地址:https://www.cnblogs.com/daxin/p/3205705.html
Copyright © 2011-2022 走看看