0
我有一個ext js組合框,我從我的控制器加載的值。以下是代碼:extjs combobox從控制器加載值
<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);
}
但是我的組合框始終是空的,不加載values.What我做錯了什麼?請幫忙!
當我使用此代碼時,我得到一個沒有任何組合框的空白頁面。 – Philomath 2013-04-28 14:48:02
試試url:'/ ComboBox/Load'而不是/ Combo/Load我在那裏。對不起,我在測試時用不同的名字設置了我的測試控制器。 – LUKE 2013-04-29 03:04:05
好吧我已經修改,然後嘗試...但是當我改變列表結構爲對象,因爲你建議,我的代碼與以前的aspx.Now我能夠看到組合框中的值..現在我想得到選定的值並將其傳遞給我的控制器。我怎麼做到這一點。我曾嘗試添加監聽器組合..但不知道如何將值傳遞給控制器。聽衆:{ select:function(combo,record,index)var value = combo.getValue(); alert(value +'clicked'); } – Philomath 2013-04-29 05:28:58