2016-03-03 74 views
0

我使用Sencha Touch 2.4,Sencha Cmd 6.1.x(所以我相信我正在使用Ext JS 6)。我有以下型号和商店:Sencha Touch:引用不生成

Ext.define('App.model.User', { 
extend: 'Ext.data.Model', 

fields: [{ 
    name: 'organizationId', 
    type :'int', 
    reference: { 
     type: 'Organization', 
     association: 'UsersByOrganization', 
     role: 'organization', 
     inverse: 'users' 
    } 
}, { 
    "name": "matricola", 
    "type": "int" 
}] 

});

Ext.define('App.model.Organization', { 
extend: 'Ext.data.Model', 
fields: ['name'] 

});

我使用通常的方式加载我的商店(使用'sql'代理),但我无法在任何地方找到我的参考。我只是获得记录,我不能称之为“用户”或其反面。

有什么想法?

回答

0

Sencha Touch 2.4和ExtJS 6是两种不同的工具包。创建模型和商店的语法在两者中都是相似的,但不是所有情况。

我相信你要找的是StoreManager。如果您已经定义了一个店,像这样:

Ext.define('App.store.User', { 
    extend: 'Ext.data.Store', 
    storeId: 'User', 
    model: 'User' 
}); 

那么你可以参考店里像这样:

// Return a list of users 
Ext.getStore('User').getRange(); 
0

下面的代码对我的作品上的Ext JS 6.也许你可以你以后这种模式例如:

Ext.define('App.model.Customer', { 
    extend: 'Ext.data.Model', 
    idProperty: 'customerNumber', 
    fields: [ 
     { name: 'customerNumber', type: 'int' }, 
     { name: 'customerName', type: 'string' }, 
     { name: 'contactLastName', type: 'string' }, 
     { name: 'contactFirstName', type: 'string' } 
    ], 
    proxy: {    
     type: 'ajax', 
     url: '../../../api/CustomersAssociationsReference', 
     reader: { 
      type: 'json', 
      rootProperty: 'customers', 
      totalProperty: 'count' 
     } 
    } 
}); 

Ext.define('App.model.Order', { 
    extend: 'Ext.data.Model', 
    idProperty: 'orderNumber', 
    fields: [ 
     { name: 'orderNumber', type: 'int' }, 
     { 
      name: 'customerNumber', reference: { 
       type: 'App.model.Customer', 
       inverse: 'orders'   
      } 
     }, 
     { name: 'orderDate', type: 'string' }, 
     { name: 'status', type: 'string' } 
    ], 
    proxy: {  // Note that proxy is defined in the Model, not the Store 
     type: 'ajax', 
     url: '../../../api/OrdersAssociationsReference', 
     reader: { 
      type: 'json', 
      rootProperty: 'orders', 
      totalProperty: 'count' 
     } 
    } 
}); 

Ext.application({ 
    name: 'App', 
    models: ['Customer', 'Order'], 
    stores: ['Customers', 'Orders'], 
    launch: function() { 

     var customersStore = Ext.getStore('Customers'); 
     customersStore.load(function (records, operation, success) { 

      var customer = records[0], 
       orders = customer.orders(), 
       order; 
      orders.load(function (records, operation, success) { 
       console.log('Orders for ' + customer.get('customerName') + ':\n-------------------------------------------------------'); 
       for (i = 0, len = records.length; i < len; i++) { 
        order = records[i]; 
        console.log('orderNumber: ' + order.get('orderNumber')); 
        console.log('orderDate: ' + order.get('orderDate')); 
        console.log('status: ' + order.get('status')); 
        console.log('-------------------------------'); 
       } 
      }) 
     }); 
    } 
});