【问题标题】:Is it possible to set Custom ID to sencha touch records是否可以将自定义 ID 设置为煎茶触摸记录
【发布时间】:2014-10-12 00:54:21
【问题描述】:

当我在 sencha touch Grid 上加载商店时,记录具有自动生成的 ID,例如“ext-records-5”、“ext-records-6”等,

我从服务器获取的列如下:“eId”、“name”、“number”

在我的 data.Model 中,我设置了 idProperty: 'eId' 假设它将来自服务器的 eId 设置为记录的 ID,但这似乎只是将 internalId 设置为 'eId'

这不是我要找的,有没有人遇到过这样的情况,或者任何人都可以找到一种方法来实现我正在寻找的东西。

任何帮助将不胜感激。

提前致谢。

【问题讨论】:

    标签: datagrid model store sencha-touch-2.3


    【解决方案1】:

    默认考虑idProperty:'id',sencha会根据你选择的identifier策略自行生成自动id,可以是simplesequentialuuid。但只要你说idProperty: 'eId',这意味着sencha 不会为你生成任何id。我们可以使用 eId,也可以通过使用字段名称作为 id 直接接受该值,如下所示。所以在下面显示的情况下,我使用了 id 而不是 eId

    Ext.define('StoreDemo.model.LSModel', {
        extend: 'Ext.data.Model',
        
        config: {
            fields: [
                { name: 'id', type: 'auto' }, // use id instead of eId
                { name: 'name', type: 'int' },
                { name: 'number', type: 'int' }
    
            ],
            idProperty:'id' , //By default idProperty is 'id'
            // idProperty:'uname' ,
            proxy:{
            	type:'localstorage' // or 'sessionstorage'
            },
    
            /*identifier:{
                type:'simple'  //The id is given by Ext e.g. ext-record-1,ext-record-2
            	// type:'uuid'  //This generates a unique id everytime we save a model
            }*/	
        }
    });

    当您通过服务器获取数据时,例如使用字段名称为 eId 的单独模型并将模型分配给上述 LSModel 的另一个模型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-27
      相关资源
      最近更新 更多