多个商店加载问题Sencha触摸



我有两个商店的民意调查和'选择',其各自的模型为"民意调查"one_answers"选择"

模型

poll

Ext.define('PollsTest.model.Poll', {
extend: 'Ext.data.Model',
xtype : 'poll', 
config: {
    fields: [
        { name: 'title'},
        { name: 'uri' },

    ],
    hasMany :
            [
                {
                    model : 'PollsTest.model.Choices',
                    name : 'Choices',
                    primaryKey : 'title',
                    foreignKey : 'title',
                    foreignStore : 'Choices'
                }
            ]
}

});

选择

Ext.define('PollsTest.model.Choice', {
extend: 'Ext.data.Model',


config: {
    fields: [
        { name: 'choice', type: 'auto' },
        { name: 'votes', type: 'auto' },
        {name : 'title', type: 'auto'},
        {name : 'uri', type : 'auto'}
    ],

belongsTo : {
                model : 'PollsTest.model.Choices',
                    name : 'Choices',
                    primaryKey : 'title',
                    foreignKey : 'title',
                    foreignStore : 'Choices',
                    getterName: 'getChoices',
                    setterName: 'setChoices'
            }        
}

});

商店

民意调查

Ext.define('PollsTest.store.Polls',{
extend : 'Ext.data.Store',
alias : 'store.pollStore',
//xtype:'pollStore',        
requires : 
            [
                'PollsTest.model.Poll',
                'Ext.data.proxy.JsonP',
                'Ext.data.reader.Json'
            ],

config :
        {   
            autoLoad : true,
            model : 'PollsTest.model.Poll',
            storeId :'pollStore',


            listeners : 
                    {
                        load : function(store, records)
                            {
                                console.log('store loaded',records);
                            }
                    },

            //storeId : 'pollstore',
            proxy : 
                {
                    type : 'jsonp',
                    url : 'http://localhost/polls',
                    reader : 
                        {
                            type : 'json',
                            rootProperty : 'polls'
                        }
                }
        },

});

选择

Ext.define('PollsTest.store.Choices',{
extend : 'Ext.data.Store',
alias : 'store.choiceStore',        
requires : 
            [
                'PollsTest.model.Choice'
            ],

config :
        {   
            autoLoad : false,
            model : 'PollsTest.model.Choice',
            storeId :'choiceStore',
            listeners : 
                {
                    load : function(store, records)
                            {
                                console.log('choice store loaded',records);
                            }
                },

            proxy :
                {
                    type : 'jsonp',
                    url : '',
                    reader : 
                        {
                            type: 'json',
                            rootProperty : 'choices'
                        }
                }

        },


});

so从 polls 存储中,我可以填充我的列表,然后单击列表项目,控制器将详细信息面板推向视图。选择存储将根据列表上发生的TAP事件填充。因此,问题是我必须将详细信息面板推到View 之后,才加载选择存储

之后

我该怎么做?建议。

我的控制器看起来像这样

Ext.define('PollsTest.controller.MainController', {
extend: 'Ext.app.Controller',

requires : ['PollsTest.controller.ChoiceController'],
config: {


    refs: {
        mainController : 'mainpanel',
        controller_list : 'pollslist',
        details_controller : 'pollsdetails'
    },
    control: {
        controller_list : 
                    {
                        itemtap : 'ShowPoll'
                    },

            }
            },
ShowPoll : function (list, index, target, record, e, eOpts)
                {   
                   var tochoice = record.data.uri;
                   var main_path = 'http://localhost';
                   var choices_url = main_path+tochoice;
                   var choice_store_object = Ext.getStore('choiceStore');
                   choice_store_object.getProxy().setUrl(choices_url);
                   choice_store_object.load();
                   console.log(choice_store_object.getCount());
                /*   var choices_store_object = Ext.create('PollsTest.store.Choices');
                   var checking = choices_store_object.on('load',function(){return true;});
                   if(checking==true) --> didn't work no detail panel pushing is happening but the order of loading the stores works fine here. 
                        {
                 */     console.log('before pushing');
                        this.getMainController().push({xtype : 'pollsdetails',data : record.data });
                        console.log('after Pushing');
                 //       }






                //this.getApplication().getController('ChoiceController').onDetailsShow(this,record,tochoice);   



                }




 });

您可以在选择商店加载功能中传递回调功能。在商店加载后将执行回调函数。

choice_store_object.load(function(records, operation, success) {
    // push the pollsdetails view here
}, this);     

这就是我实现的方式

var choices_store_object = Ext.create('PollsTest.store.Choices');
                   var checking =choice_store_object.load(function(records, operation, success)
                    {

                                    console.log('before pushing');
                                    this.getMainController().push({xtype : 'pollsdetails',data : record.data });
                                    console.log('after Pushing');            



                   }, this);

`

最新更新