我想创建一个包含2个项目的组合框。项目文本应以不同格式显示DateTime.Now
。组合框是行扩展器。这是组合的代码:
<ext:ComboBox runat="server" ID="cmbFormatFFC" DataIndex="DateFormat" FieldLabel="Date Format" Width="400" ForceSelection="true" EmptyText="Select date format...">
<Listeners>
<BeforeRender Handler="#{DirectMethods}.fillComboDates()" />
和代码隐藏:
[DirectMethod]
public void fillComboDates()
{
cmbFormatFFC.Items.Insert(0,new Ext.Net.ListItem(DateTime.Now.ToString("d/M/yyyy"), "d/M/yyyy"));
cmbFormatFFC.Items.Insert(1,new Ext.Net.ListItem(DateTime.Now.ToString("dd-MMM-yyyy"), "dd-MMM-yyyy"));
}
但是,当我在应用程序中展开行时,我收到此错误:
未捕获的TypeError:无法设置null
的属性'component'
答案 0 :(得分:2)
您无法使用BeforeRender加载商店数据。它发生在控制生命周期的早期。您最好的解决方案是在RowExpander上使用BeforeExpand事件。此外,由于您的ComboBox中有静态数据,因此您只想执行一次DirectEvent。这是一个例子:
*。ASPX
<ext:GridPanel ID="grid" runat="server">
<ColumnModel>
<Columns>
<ext:Column runat="server" DataIndex="Field1" />
</Columns>
</ColumnModel>
<Store>
<ext:Store runat="server" ID="store">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="Field1" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<Plugins>
<ext:RowExpander runat="server">
<Component>
<ext:ComboBox runat="server" ValueField="Key" DisplayField="Display">
<Store>
<ext:Store runat="server" ID="comboStore" OnReadData="Store_ReadData">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="Key" />
<ext:ModelField Name="Display" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
</ext:ComboBox>
</Component>
<Listeners>
<BeforeExpand Handler="if (comboStore.getCount() == 0) comboStore.reload();" />
</Listeners>
</ext:RowExpander>
</Plugins>
</ext:GridPanel>
*。aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack || X.IsAjaxRequest)
return;
store.DataSource = new object[]
{
new { Field1 = "Row 1" },
new { Field1 = "Row 2" },
new { Field1 = "Row 3" }
};
store.DataBind();
}
protected void Store_ReadData(object sender, StoreReadDataEventArgs e)
{
comboStore.DataSource = new object[]
{
new { Key = DateTime.Now.ToString("d/M/yyyy"), Display = "d/M/yyyy" },
new { Key = DateTime.Now.ToString("dd-MMM-yyyy"), Display = "dd-MMM-yyyy" }
};
comboStore.DataBind();
}
答案 1 :(得分:0)
确保您的组合已成功初始化,并且您的方法fillComboDates()返回值
答案 2 :(得分:0)
可能是由Ext.Net生成并发送给客户端的JS在呈现cmbFormatFFC
之前正在执行。为确保以后发生这种情况,您可以将侦听器从BeforeRender
更改为BoxReady
。