【问题标题】:Sencha Touch: reference not generatedSencha Touch:未生成参考
【发布时间】:2016-03-03 14:54:31
【问题描述】:

我使用的是 Sencha Touch 2.4,带有 Sencha Cmd 6.1.x(所以我相信我使用的是 Ext JS 6)。我有以下模型和商店:

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”代理),但我无法在任何地方找到我的参考。我只是得到记录,我不能称“用户”或它的反义词。

有什么想法吗?

【问题讨论】:

    标签: extjs touch


    【解决方案1】:

    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();
    

    【讨论】:

      【解决方案2】:

      下面的代码在 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('-------------------------------');
                      }
                  })
              });
          }
      });
      

      【讨论】:

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