使用我想從Yii的控制器動作數據Ext.data.store與下面的代碼:extjs4 data.store與代理
var vehicles = new Ext.data.Store({
reader: new Ext.data.JsonReader({
fields: ['vehiclename'],
root: 'vehicles'
}),
proxy: new Ext.data.HttpProxy({
url: '<?php echo $this->createUrl('GetVehicles');?>'
}),
autoLoad: true
});
或以下的車輛代碼:
var vehicles = Ext.create('Ext.data.Store', {
fields: [
{name: 'vehiclename'}
],
proxy: {
type: 'ajax',
url: '<?php echo $this->createUrl('GetVehicles'); ?>',
reader: {
type: 'json',
root:'vehicles'
}
},
autoLoad: true
});
我行動代號爲:
public function actionGetVehicles()
{
$sql = "select vehicleName from vehicletbl inner join companytbl on vehicletbl.companyid=companytbl.companyid and companytbl.companyid='2';";
$vehicles = Yii::app()->db->createCommand($sql)->queryAll();
//var_dump($vehicles);
echo '{vehicles:'.json_encode($vehicles).'}';
}
當我請求發送到與瀏覽器地址欄的動作我獲得以下JSON:
{vehicles:[{"vehiclename":"pride"},{"vehiclename":"benz"}]}
但我不知道爲什麼Ext.data.store無法獲取數據和存儲主題!
我的代碼有什麼問題?
我用儲存在:
items: [treePanel,Ext.create('Ext.grid.PropertyGrid', {
title: 'History',
closable: false,
header: true,
sortableColumns: false,
customEditors: {
Vehicle: Ext.create('Ext.form.ComboBox', {
store: vehicles,
queryMode: 'local',
displayField: 'vehiclename'
})
},
/*propertyNames: {
'evtStart': 'Start Time'
},*/
source: {
"Vehicle": 'Select Vehicle',
"Select Start Date": false,
"Select End Date": true
}
})]
Chrome開發者工具輸出:
我在我的ComboBox中使用'displayField:'name''並且沒有顯示數據,我將它改爲'displayField:'vehiclename'',並且每件事情都沒問題! – taher