在extjs中如何将store绑定到另一个视图中作为项目包含的视图

时间:2013-03-08 09:09:09

标签: view extjs4 store

我在extjs工作。我认为 - QbqnsResultmain.js

Ext.define('Balaee.view.qb.qbqns.QbqnsResultmain',  
        {
    extend:'Ext.form.Panel',
    requires:[
              'Balaee.view.qb.qbqns.QbqnsResult'
              ],
              id:'QbqnsResultmainId',
              alias:'widget.QbqnsResultmain',
              title:'Result',
              height:400,
              items:[
                     {
                         xtype:'QbqnsResult',

                     },
                     ],
                     buttons:[
                              {
                                  xtype:'button',
                                  fieldLabel:'review',
                                  action:'getreview',
                                  name:'review',
                                  formBind:true,
                                  text:'Review',

                              },
                              {
                                  xtype:'button',
                                  fieldLabel:'papers',
                                  action:'getpapers',
                                  name:'papers',
                                  formBind:true,
                                  text:'Get all papers',
                             },
                           ]});

和QbqnsResult.js -

Ext.define('Balaee.view.qb.qbqns.QbqnsResult',
{
        extend:'Ext.view.View',
        id:'QbqnsResultId',
        alias:'widget.QbqnsResult',
        //store:'kp.PollStore',
        store:'qb.QbqnsStore',
        config:
        {
            tpl:'<tpl for="1">'+
                '<div id="main">'+
                '</br>'+
                //'<b>Question :-</b></br>'+
                '<h1 id="q">Total number of Questions are:-</h1>{TotalQuestions}</br>'+
                '<h1 id="q">Number of attempted Questions:-</h1> {Attempted}</br>'+
                '<h1 id="q">Number of correct answers:-</h1> {CorrectAnswers}</br>'+
                '<h1 id="q">Total score:-</h1> {Total}</br>'+
                '<h1 id="q">Score you got is:-</h1> {Score}</br>'+
                '<h1 id="q">percentage you got is:-</h1> {percentage}</br>'+

            '<p>---------------------------------------------------------</p>'+
                '</div>'+
                '</tpl>',
            itemSelector:'div.main',    
        }
});

点击提交按钮,我想显示上面的视图。所以我在控制器中编写了代码 -

check:function()
    {
    var resultStore=Ext.create('Balaee.store.qb.QbqnsStore');
            proxy=resultStore.getProxy();
            Ext.apply(proxy.api,{
            read:'index.php/QuestionBank/qbpaper/getResult',
            create:'index.php/QuestionBank/qbpaper/getResult'
            });

            Ext.apply(proxy.reader,{
                type:'json',
                //root:'polls',
                root:'questions'
            });

            Ext.apply(proxy.writer,{
                type:'json',
                //root:'polls',
                root:'data'
            });


        var getdata=this.getLocalvalue();
        console.log(getdata.data);
        Paperno=getdata.data.questionPaperNo;
        UserId=getdata.data.userId;

        var answers = '{"data":[';
        answers = answers + '{"paperNo":"'+Paperno+'","userId":"'+UserId+'"}';
        answers =answers+']}';
        console.log(answers);

        resultStore.load({
            params:{
                data: answers
            },
            callback: function(records,operation,success){
                console.log(records);
                console.log("Successfully data send");
            },
            scope:this
        });

        var temp= Ext.getCmp('qbqnsId');
        temp.removeAll();


        var worldChaptor3 =temp.add({xtype:'QbqnsResultmain',
                id:'QbqnsResultmainId',
                store:resultStore});

},

所以我想将resultStore绑定到QbqnsResult视图的tpl,我在QbqnsResultmain视图中将其作为xtype包含在内。但是resultStore被绑定到Qbqnsresultmain视图,但没有绑定到Qbqnsresult,它通过其xtype作为项目包含在其中。那么如何将商店绑定到它。有人可以指导我吗

1 个答案:

答案 0 :(得分:0)

一种方法可以是:

var worldChaptor3 =temp.add({xtype:'QbqnsResultmain',
            id:'QbqnsResultmainId',
            store:resultStore});

worldChaptor3.down('QbqnsResultmain > QbqnsResult').bindStore(resultStore);

但是,如果你在QbqnsResultmain中执行它会更好,我会在afterrender事件上执行此操作,这样,您可以在创建时自动绑定存储。