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

  • 相关阅读:
    BZOJ 2226 [Spoj 5971] LCMSum | 数论拆式子
    BZOJ 2705: [SDOI2012]Longge的问题 | 数论
    BZOJ 1257[CQOI2007]余数之和sum | 数论
    BZOJ 3781: 小B的询问 | 莫队
    文件切割与合并
    [科普贴]为何Flash被淘汰?附Chrome看视频最完美教程!
    JQ模仿select
    JS正则表达式
    Vuejs——Vue生命周期,数据,手动挂载,指令,过滤器
    Vuejs——v-on
  • 原文地址:https://www.cnblogs.com/daxin/p/3205705.html
Copyright © 2011-2022 走看看