用coolite开发的项目,也需要用到comboTree,千辛万苦,终于和老外要到了代码。
JS
2 /**** @class ComboTree* @extends Ext.form.ComboBox*/
3 Ext.ux.ComboTree = Ext.extend(Ext.form.ComboBox, {
4 extStore: null,
5 tree: null,
6 treeId: 0,
7 setValue: function (v) {
8 var text = v;
9 if (this.valueField) {
10 var r = this.findExtRecord(this.valueField, v);
11 if (r) {
12 text = r.data[this.displayField];
13 } else if (this.valueNotFoundText !== undefined) {
14 text = this.valueNotFoundText;
15 }
16 }
17 Ext.ux.ComboTree.superclass.setValue.call(this, text);
18 this.lastSelectionText = text;
19 if (this.hiddenField) {
20 this.hiddenField.value = v;
21 }
22 this.value = v;
23 },
24 initComponent: function () {
25 this.treeId = Ext.id();
26 this.focusLinkId = Ext.id();
27 Ext.apply(this, {
28 store: new Ext.data.SimpleStore({
29 fields: [],
30 data: [[]]
31 }),
32 editable: false,
33 shadow: false,
34 mode: 'local',
35 triggerAction: 'all',
36 maxHeight: 200,
37 tpl: '<tpl for="."><div style="height:200px"><div >
ComboTree.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Web.UI;
using Coolite.Ext.Web;
[assembly: WebResource("Coolite.Ext.UX.Extensions.ComboTree.resources.ComboTree.js", "text/javascript")]
namespace Coolite.Ext.UX
{
[Designer(typeof(EmptyDesigner))]
[DefaultProperty("")]
[Xtype("combotree")]
[InstanceOf(ClassName = "Ext.ux.ComboTree")]
[ClientScript(Type = typeof(ComboTree), WebResource = "Coolite.Ext.UX.Extensions.ComboTree.resources.ComboTree.js", FilePath = "ux/extensions/combotree/combotree.js")]
[ToolboxData("<{0}:ComboTree runat=\"server\" Title=\"Combo tree\" Height=\"300\"></{0}:ComboTree>")]
[Description("Combobox with tree functionality")]
public class ComboTree : ComboBox
{
private ItemsCollection<TreePanel> tree;
[ClientConfig("tree", typeof(ItemCollectionJsonConverter))]
[Category("Config Options")]
[NotifyParentProperty(true)]
[DefaultValue(null)]
[PersistenceMode(PersistenceMode.InnerProperty)]
public virtual ItemsCollection<TreePanel> Tree
{
get
{
if (this.tree == null)
{
this.tree = new ItemsCollection<TreePanel>();
}
return this.tree;
}
}
protected override void OnLoad(EventArgs e)
{
this.Controls.Add(Tree[0]);
if (!this.LazyItems.Contains(Tree[0]))
{
this.LazyItems.Add(Tree[0]);
}
base.OnLoad(e);
}
}
}