有朋友通过Ext.data.DirectStore给combobx绑定过数据么
代码如下
xtype: 'combobox',
id: 'ctlEMS_NO',
editable: true,
queryMode: 'local',
typeAhead: true,
selectOnFocus: true,
store: Ext.create('Ext.data.Store', {
model: 'dropModel',
proxy: {
type: 'direct',
directFn: app.Method.Code,
reader: {
type: 'json',
root: 'data'
},
},
autoLoad: true
}),
displayField: 'Text',
valueField: 'Value',
fieldLabel: '编码',
triggerAction: 'all',
emptyText: '请选择'
}这样绑定的话虽然后台返回了数据,但是绑定不到combobox上,但是用下面一种却没问题 xtype: 'combobox',
id: 'ctlEMS_NO',
editable: true,
queryMode: 'local',
typeAhead: true,
selectOnFocus: true,
store: Ext.create('Ext.data.Store', {
model: 'dropModel',
proxy: {
type: 'ajax',
url: '../modulehelp.ashx?action=Code',
reader: {
type: 'json',
root: 'data'
},
},
autoLoad: true
}),
displayField: 'Text',
valueField: 'Value',
fieldLabel: '编码',
triggerAction: 'all',
emptyText: '请选择'
}有用过的朋友给我点提示呢,谢谢啦
代码如下
xtype: 'combobox',
id: 'ctlEMS_NO',
editable: true,
queryMode: 'local',
typeAhead: true,
selectOnFocus: true,
store: Ext.create('Ext.data.Store', {
model: 'dropModel',
proxy: {
type: 'direct',
directFn: app.Method.Code,
reader: {
type: 'json',
root: 'data'
},
},
autoLoad: true
}),
displayField: 'Text',
valueField: 'Value',
fieldLabel: '编码',
triggerAction: 'all',
emptyText: '请选择'
}这样绑定的话虽然后台返回了数据,但是绑定不到combobox上,但是用下面一种却没问题 xtype: 'combobox',
id: 'ctlEMS_NO',
editable: true,
queryMode: 'local',
typeAhead: true,
selectOnFocus: true,
store: Ext.create('Ext.data.Store', {
model: 'dropModel',
proxy: {
type: 'ajax',
url: '../modulehelp.ashx?action=Code',
reader: {
type: 'json',
root: 'data'
},
},
autoLoad: true
}),
displayField: 'Text',
valueField: 'Value',
fieldLabel: '编码',
triggerAction: 'all',
emptyText: '请选择'
}有用过的朋友给我点提示呢,谢谢啦
Ext4 Ext.data.proxy.Direct directFn示例
[DirectAction("Method")]
public class DirectAPI : DirectHandler
{
public override string ProviderName
{
get
{
return "app.Route";
}
} public override string Namespace
{
get
{
return "app";
}
}
[DirectMethod]
public string TRADE_CODE()
{
return GetJSON("select cast(TRADE_CODE as varchar(30)) [Value],TRADE_CODE+'|'+TRADE_NAME [Text] from COP_BIZ");
} private string GetJSON(string Sql)
{ SqlHelper _sqlHelper = new SqlHelper();
JArray _jarray = new JArray();
IDataReader dReader = _sqlHelper.ExecuteReader(Sql.ToString());
while (dReader.Read())
{
_jarray.Add(new JObject(
new JProperty("Value", dReader["Value"]),
new JProperty("Text", dReader["Text"])
));
}
return new JObject(
new JProperty("data", _jarray)
).ToString();
}
}
//前台代码
Ext.onReady(function () {
Ext.direct.Manager.addProvider(app.Route); Ext.define("dropModel", { extend: "Ext.data.Model", fields: [{ name: "Value" }, { name: "Text" }] }); var win;
if (!win) {
win = Ext.create('widget.window', {
closable: false,
closeAction: 'hide',
width: 530,
minWidth: 530,
height: Ext.isIE ? 302 : 310,
autoShow: true,
border: true,
bodyStyle: 'text-align:right;',
iconCls: 'x-icon-add',
layout: {
type: 'border',
},
items: [{
region: 'center',
xtype: 'panel',
border: false,
layout: {
type: 'border'
},
items: [{
region: 'north',
xtype: 'panel',
border: false,
heigth: 170,
contentEl: 'ShowLogo'
}, {
region: 'center',
layout: {
type: 'border'
},
xtype: 'form',
id: "formPanel",
items: [{
region: 'center',
xtype: 'panel',
bodyStyle: 'background-color: transparent;',
border: false,
layout: 'form',
items: [{
xtype: 'combobox',
id: 'ctlEMS_NO',
editable: true,
queryMode: 'local',
typeAhead: true,
selectOnFocus: true,
store: Ext.create('Ext.data.Store', {
model: 'dropModel',
storeid:'test',
proxy: {
type: 'direct',
batchActions: false,
directFn: app.Method.code,
reader: {
type: 'json',
root: 'data'
},
},
autoLoad: true
}),
displayField: 'Text',
valueField: 'Value',
fieldLabel: '交易代码',
triggerAction: 'all',
emptyText: '请选择'
}]
}]
}
]
}]
});
}});后台返回数据{ "data": [ { "Value": "0000001", "Text": "0000001|直接付款" } ] }