2016-03-03 3 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('-------------------------------'); 
       } 
      }) 
     }); 
    } 
});