我还尝试了以下代码......使用处理程序
在Index.aspx
中<ext:Store ID="Store1" IsPagingStore="true" runat="server">
<Proxy>
<ext:AjaxProxy Url="../../Shared/JsonHandler.ashx">
<ActionMethods Read="GET" />
<Reader>
<ext:JsonReader Root="names" />
</Reader>
</ext:AjaxProxy>
</Proxy>
<Model>
<ext:Model ID="Model1" runat="server">
<Fields>
<ext:ModelField Name="name" Type="String" Mapping="nameList" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
在JsonHandler.ashx
中 public void ProcessRequest(HttpContext context)
{
context.Response.ContentType ="text/json";
var requestParams = new StoreRequestParameters(context);
FormExampleController ex=new FormExampleController ();
var list = ex.getValue();
context.Response.Write(string.Format("{{'Names':{0}}}",JSON.Serialize(list)));
}
在FormController中
public List<string> getValue()
{
FormUser user = new FormUser();
user.nameList = new List<string>
{
"A",
"B",
"C",
"D"
};
return user.nameList;
}
这里的值再次传递给处理程序,但组合框显示为空!!有什么建议吗?
答案 0 :(得分:0)
似乎无法将Store
绑定到简单的List
或Array
字符串。
以下是应该有效的测试用例,但没有。我正在研究解决方案,很快就会发布更新。
示例强>
<%@ Page Language="C#" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
var store = this.ComboBox1.GetStore();
store.DataSource = new List<string> { "A", "B", "C", "D" };
store.DataBind();
}
</script>
<!DOCTYPE html>
<html>
<head runat="server">
<title>Ext.NET Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:ComboBox ID="ComboBox1" runat="server" DisplayField="name">
<Store>
<ext:Store runat="server">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="name" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
</ext:ComboBox>
</form>
</body>
</html>
以下示例绑定到一个简单的List<object>
,虽然显然这不是原始问题的解决方案,但我在此处作为可能的临时解决方法。
示例强>
<%@ Page Language="C#" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
var store = this.ComboBox1.GetStore();
store.DataSource = new List<object> {
new { name = "A" },
new { name = "B" },
new { name = "C" },
new { name = "D" }
};
store.DataBind();
}
</script>
<!DOCTYPE html>
<html>
<head runat="server">
<title>Ext.NET Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:ComboBox ID="ComboBox1" runat="server" DisplayField="name">
<Store>
<ext:Store runat="server">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="name" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
</ext:ComboBox>
</form>
</body>
</html>
答案 1 :(得分:0)
是的,Store不支持这种简单的结构。存储期望对象的集合(对象应包含在模型中定义为字段的属性)
您应该将您的字符串列表转换为对象列表,例如
(new List<string>{"a", "b", "s"}).Select(s => new {FieldName = s})