0

我正在使用select fiield在我的项目中加载国家/地区。我从数据库加载数据。当我使用autoload时,它非常完美:在我的商店中是true。 但是,当我使用自动加载时,它不会加载:false,并手动加载它。Sebcha Touch选择字段加载问题

附加示例代码,

在此先感谢。

商店

Ext.define("MyProject.store.CountryStore", { extend: 'Ext.data.Store', 
    storeId: "countryStore", 
    config: { 
     model: "MyProject.model.CountryModel", 
     autoLoad: false, //this is the issue 
     header: { 
      "Content-Type": "application/json" 
     }, 
     proxy: { 
      type: 'ajax', 
      url: MyProject.Config.config.webService + 'GetCountries', 
      //extraParams: { 
      // sessionId: sessionId 
      //}, 
      reader: { 
       type: 'json', 
       rootProperty: 'd.countries' 
      }, 
      actionMethods: { 
       create: 'POST', 
       read: 'POST', 
       update: 'POST', 
       destroy: 'POST' 
      }, 
      writer: { 
       encodeRequest: true, 
       type: 'json' 
      } 
     } 
    } 
}); 

控制器

var CountryStore = Ext.create('MyProject.store.CountryStore', {       }); 


      CountryStore.getProxy().setExtraParams({ 
       sessionId: sessionId 
      }); 
      CountryStore.load({ 
      }); 

视图

{    xtype: 'selectfield', 
       name: 'country', 
       label: 'Country', 
       store: 'CountryStore', 
       valueField: 'code', 
       displayField: 'name', 
       placeHolder: 'Select your country' 
} 

模型

Ext.define("MyProject.model.CountryModel", { 
    extend: 'Ext.data.Model', 
    config: { 
     idProperty: 'Id', 
     fields  : [ 
      { name: 'code'}, 
      { name: 'name'} 
     ] 
    } 
}); 

回答

0

将商店设置为名称时,您使用控制器的商店,它是控制器所有视图的全球商店。如果你想使用用户定义存储,你需要通过它来查看。

Ext.define('YourProject.controller.YourController', {  
    ... 

    sessionId: 'someId', 

    init: function() { 
     var me = this; 

     me.control({ 
      scope: me, 

      'yourviewname': { 
       afterrender: me.onViewAfterRender 
      } 
     }); 

     me.callParent(arguments); 
    }, 

    onViewAfterRender: function(view) { 
     var store = view.getStore(); 

     if (store) { 
      store.getProxy().setExtraParams({ 
       sessionId: sessionId 
      }); 

      store.load(); 
     } 
    } 

    ... 
}); 

Ext.define('YourProject.view.YourView', { 
    ... 
    alias: 'widget.yourviewname', 
    requires: ['YourProject.store.CountryStore'], 

    initComponent: function() { 
     var me = this, 
      countryStore = Ext.create('YourProject.store.CountryStore', {}); 

     Ext.applyIf(me, { 
      ... 

      items: [ 
       { 
        xtype: 'selectfield', 
        name: 'country', 
        label: 'Country', 
        store: countryStore, 
        valueField: 'code', 
        displayField: 'name', 
        placeHolder: 'Select your country' 
       } 
      ] 
     }); 
    } 
}); 
+0

非常感谢您的快速回复。没有其他方法可以做到吗?因为我需要保持我的视图干净(没有任何功能)。无论如何在控制器中都没有吗? – Kasun 2014-09-25 06:30:32

+0

我在控制器中添加业务逻辑 – 2014-09-25 10:54:41

+0

这是正确的。我也打算这样做。非常感谢你。 – Kasun 2014-09-26 19:48:44

0

我解决它终于:)

当我设置店从控制工程:)

myView.items.items[9].setStore(CountryStore);