我正在使用extjs + Yii框架。我的服务器端在Yii,客户端在extjs。我将yii框架输出以extjs作为输入。现在从Yii的我发送JSON:如何为json文件创建extjs视图
CJSON::encode(array("questionId"=>$questionid,"question"=>Question,"Options"=>$optionList,"CorrectOptionId"=>$CorrectId,"UserSelectedOption"=>$Usersoption));
所以我得到的JSON输出:
{"Questions":[
{
"questionId": 1,
"question": 'Who will win the series1212?',
"options": [
{
"optionId":1,
"option":'Aus',
"questionId":1
},
{
"optionId": 1,
"option": 'india',
"questionId":1
},
{
"optionId": 1,
"option": 'England',
"questionId":1
},
]
"CorrectOptionId":1,
"UserSelectedOption":2,
} ,{-------}
]
}
我已经MVC格式代码:
QbqnsModel.js
Ext.define('Balaee.model.qb.QbqnsModel',{
extend: 'Ext.data.Model',
idproperty:'questionId',//fields property first position pk.
fields: ['questionId','question','languageId','userId','creationTime','questionStatusId','keyword'],
hasMany:{
model:'Balaee.model.qb.QbqnsoptionModel',
foreignKey:'questionId',
name:'options',
},
proxy:
{
type:'ajax',
api:
{
},//end of api
reader:
{
type:'json',
},//end of reader
writer:
{
type:'json',
},//End of writer
}
QbQnsStore.js
Ext.define('Balaee.store.qb.QbqnsStore',{
extend: 'Ext.data.Store',
model: 'Balaee.model.qb.QbqnsModel',
autoLoad: true,
proxy:
{
type:'ajax',
api:
{
read:'data/question.json',
},
reader:
{
type:'json',
root:'questions',
}
}
});
而且Qbqnsview.js AS-
Ext.define('Balaee.view.qb.qbqns.QbqnsView',
{
extend:'Ext.view.View',
id:'qbqnsViewId',
alias:'widget.QbqnsView',
//store:'kp.PollStore',
store:'qb.QbqnsStore',
config:
{
tpl:'<tpl for=".">'+
'<div id="main">'+
'</br>'+
// '<b>Question :-</b> {pollQuestion}</br>'+
'<h1 id="q">Question :-</h1> {question}</br>'+
'<tpl for="options">'+ // interrogate the kids property within the data '<tpl if="optionId == parent.UserSelectedOption && optionId != parent.CorrectOptionId">'+
'<p>  <input type="radio" name="{parent.questionId}" value="{option}" class="red"> {option}</p>'+
'</tpl>'+
'<tpl if="optionId == parent.CorrectOptionId">'+
'<p>  <input type="radio" name="{parent.questionId}" value="{option}" class="green"> {option}</p>'+
'</tpl>'+
'<tpl if="optionId != parent.CorrectOptionId && optionId != parent.UserSelectedOption">'+
'<p>  <input type="radio" name="{parent.questionId}" value="{option}"> {option}</p>'+
'</tpl>'+
'</tpl></p>'+
'<p>---------------------------------------------------------</p>'+
'</div>'+
'</tpl>',
itemSelector:'div.main',
}
});// End of login class
这是正确显示的问题和它的选项。现在点击按钮,我想再次显示所有问题,选项,其实际的正确选项和用户选择的选项。 所以我想要将上面的json输出绑定到extjs存储并且想要创建视图来显示问题,它通过单选按钮的选项,正确的绿色选项。那么如何设计extjs部分来显示这样的视图。我是很新的ExtJS的......所以,你可以请指导我...
先生....我作出上述变更.Bot correctoptionId和Userselectedoption字段不在表中。所以它不访问这些字段。那么我需要做什么? – user1947777