前台:
// 后台接口数据
var dataStore = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: 'store/getStoreInfo.action' }),
reader: new Ext.data.JsonReader(
{ nameList: "" }, //后台获得的数据,传给前台的数据集合
["storeName"] //json字符串的key
)
});
dataStore.load();
// 下拉框
var storeName = new Ext.form.ComboBox({
fieldLabel : "名称",
name:'storeName',
id:'storeName',
displayField: 'storeName', //显示的字段
triggerAction : 'all',
store: dataStore,
mode : 'local', // 数据会自动读取,如果设置为local又调用了store.load()则会读取2次;也可以将其设置为local,然后通过store.load()方法来读取
editable : false,
anchor : '100%',
})
后台:
public void getStoreInfo() throws BusinessException{
//从数据库中获得数据
List<ProductionOfEvidenceVO> nameList = this.baseService.findObjects("store.getStoreInfo", null);
this.writeJson(nameList);//向前台传递json数据
}
本文介绍了一个简单的前后端交互示例,展示了如何从前端发起请求获取后台数据,并将这些数据显示在一个下拉框中。具体实现包括了使用ExtJS库创建数据存储、加载数据以及配置下拉框等步骤。
253





