如何在extjs中绑定yii操作

如何在extjs中绑定yii操作,yii,extjs4,Yii,Extjs4,我在extjs+Yii中工作。我的行动是: public function actionCreateNew() { $record=Qbquestionset::model()->findAllByAttributes(array("questionPaperId"=>1)); foreach($record as $rec) { if($rec==NULL) { echo"Paper does not

我在extjs+Yii中工作。我的行动是:

public function actionCreateNew()
{
    $record=Qbquestionset::model()->findAllByAttributes(array("questionPaperId"=>1));

    foreach($record as $rec)
    {
        if($rec==NULL)
        {
            echo"Paper does not exists";
        }
        else
        {
            echo $rec->questionId;
            $record1=Qbquestion::model()->findByAttributes(array("questionId"=>$rec->questionId));
            echo "</br>". $record1->question;
            echo "</br>".CJSON::encode(array("Question"=>$record1->question));
        }

    }
}
Store.js===

Ext.define('Balaee.store.Question', {
extend: 'Ext.data.Store',
model: 'Balaee.model.Question',
autoLoad: true,
proxy:{
    type: 'ajax',
    //url:'data/poll.json',
    api: {
        //read: 'data/question.json',
        read: 'http://localhost/NewQuestion/index.php?r=QuestionBank/qbpaper/CreateNew',
    },
    reader: {
        type: 'json',
        //root: 'questions',
    }
}
});
视图===questionView.js

Ext.define('Balaee.view.question.QuestionView',
{
    extend:'Ext.view.View',
    id:'QuestionViewId',
    alias:'widget.questionView',
    store:'Question',
    config:
    {
        tpl:'<tpl for=".">'+
            '<div id="main">'+
            '</br>'+
            '<b>Question :-</b> {Question}</br>'+
            //'<p>-------------------------------------------</p>'+

            //'<tpl for="options">'+     // interrogate the kids property within the data
                //'<p>&nbsp&nbsp<input type="radio" name="opt" >&nbsp{option}</p>'+
            //'</tpl></p>'+

            '</div>'+
            '</tpl>',
        itemSelector:'div.main',    
    }
});// 
Ext.define('Balaee.view.question.QuestionView',
{
扩展:'Ext.view.view',
id:'QuestionViewId',
别名:'widget.questionView',
商店:'问题',
配置:
{
第三方物流:''+
''+
“
”+ '问题:-{问题}
'+ //“-----------------------------------------

”+ //“”+//查询数据中的kids属性 //“{option}

”+ //“

”+ ''+ '', itemSelector:'div.main', } });//

因此,我通过提及其url将yii操作绑定到存储。但存储区未检索任何值。那么,在extjs存储中检索yii optputs需要做哪些更改呢

我看到的一个问题是你的Yii行动。您应该返回JSON结果,同时返回一些奇怪的内容

试试这个:

public function actionCreateNew()
{
    $record = Qbquestionset::model()->findAllByAttributes(array("questionPaperId" => 1));
    $result = array();
    foreach($record as $rec) {
        if ($rec != NULL) {
            $result[] = $record1->question;
        }
    }

    echo CJSON::encode(array(
        'success' => true,
        'root' => $result,
        'total' => count($result)
    ));
}

您还应该定义reader的
root:'root'
属性。

我看到的一个问题是您的Yii操作。您应该返回JSON结果,同时返回一些奇怪的内容

试试这个:

public function actionCreateNew()
{
    $record = Qbquestionset::model()->findAllByAttributes(array("questionPaperId" => 1));
    $result = array();
    foreach($record as $rec) {
        if ($rec != NULL) {
            $result[] = $record1->question;
        }
    }

    echo CJSON::encode(array(
        'success' => true,
        'root' => $result,
        'total' => count($result)
    ));
}
您还应该定义读取器的
root:'root'
属性