coolite ComboxTree
用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 id="' + this.treeId + '"></div></div></tpl>',
38 selectedClass: '',
39 onSelect: Ext.emptyFn,
40 valueField: 'id'
41 });
42 this.tree = new Coolite.Ext.TreePanel(this.tree);
43 this.on('expand', this.onExpand);
44 this.tree.on('click', this.onClick, this);
45 Ext.ux.ComboTree.superclass.initComponent.apply(this, arguments);
46 },
47 findExtRecord: function (prop, value) {
48 var record;
49 if (this.extStore != null) {
50 if (this.extStore.getCount() > 0) {
51 this.extStore.each(function (r) {
52 if (r.data[prop] == value) {
53 record = r;
54 return false;
55 }
56 });
57 }
58 }
59 return record;
60 },
61 onClick: function (node) {
62 if (node.attributes.parameter == 9) { // } else { // this.setValue(node.text); this.hiddenField.value = node.id; this.collapse(); } }, onExpand: function() { this.tree.render(this.treeId); }});Ext.reg("combotree", Ext.ux.ComboTree);
63
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);
}
}
}