我有一个 ext js 组合框,它的值是从我的控制器加载的。以下是代码:
<script type="text/javascript">
Ext.onReady(function () {
var combo = Ext.data.Record.create([
{
name: 'Name',
type: 'string'
}
]);
var writer = new Ext.data.JsonWriter({
encode: false,
listful: true,
writeAllFields: true
});
var reader = new Ext.data.JsonReader({
totalProperty: 'total',
successProperty: 'success',
idProperty: 'Name',
root: 'data',
messageProperty: 'message' // <-- New "messageProperty" meta-data
}, combo);
var proxy = new Ext.data.HttpProxy({
api: {
read: '/ComboBox/Load'
},
headers: { 'Content-Type': 'application/json; charset=UTF-8' }
});
var store = new Ext.data.Store({
id: 'Name',
proxy: proxy,
reader: reader,
writer: writer, // <-- plug a DataWriter into the store just as you would a Reader
autoSave: false // <-- false would delay executing create, update, destroy requests until specifically told to do so with some [save] buton.
});
store.load();
Ext.data.DataProxy.addListener('exception', function (proxy, type, action, options, res) {
Ext.Msg.show({
title: 'ERROR',
msg: res.message,
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
});
});
var editor = new Ext.ux.grid.RowEditor({
saveText: 'Update'
});
var numberField = new Ext.form.ComboBox({
fieldLabel: 'Name',
hiddenName: 'Name',
store:store,
displayField: 'Name',
typeAhead: true,
mode: 'local',
triggerAction: 'all',
emptyText: 'Choose number...',
selectOnFocus: true,
pageSize: 50,
labelWidth: 50,
width: 300,
padding: '60 0 0 0',
renderTo: Ext.getBody()
});
})
在我的控制器中,我有一个加载功能
public JsonResult Load()
{
List<string> my_values = new List<string>();
my_values.Add("aaaa");
my_values.Add("bbbb");
my_values.Add("cccc");
my_values.Add("dddd");
my_values.Add("eeee");
return Json(new
{
total = my_values.Count,
data = my_values,
}, JsonRequestBehavior.AllowGet);
}
但是我的组合框总是空的并且不加载值。我做错了什么?请帮忙!