CooliteToolkit(v8.0)用ComBoxTree封装的TreeCombo控件(2)


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.Web.Build.Resources.Coolite.ux.extensions.ComboTree.ComboTree.js", "text/javascript")]

namespace Coolite.Ext.Web
{
    [Designer(typeof(EmptyDesigner))]
    [DefaultProperty("")]
    [Xtype("combotree")]
    [InstanceOf(ClassName = "Ext.ux.ComboTree")]
    // FilePath = "/ux/extensions/combotree/combotree.js",
    [ClientScript(Type = typeof(ComboTree),
        WebResource = "Coolite.Ext.Web.Build.Resources.Coolite.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);
        }
    }
}


ComboTree.js 代码:

Ext.namespace('Ext.ux');
/**
*
* @class ComboTree
* @extends Ext.form.ComboBox
*/
Ext.ux.ComboTree = Ext.extend(Ext.form.ComboBox, {
    tree: null,
    treeId: 0,
    setValue: function(v) {
        var text = v;
        if (this.valueField) {
            var r = this.findExtRecord(this.valueField, v);
            if (r) {
                text = r.data[this.displayField];
            } else if (this.valueNotFoundText !== undefined) {
                text = this.valueNotFoundText;
            }
        }
        Ext.ux.ComboTree.superclass.setValue.call(this, text);
        this.lastSelectionText = text;
        if (this.hiddenField) {
            this.hiddenField.value = v;
        }
        this.value = v;
    },
    initComponent: function() {
        this.treeId = Ext.id();
        this.focusLinkId = Ext.id();
        Ext.apply(this, {
            store: new Ext.data.SimpleStore({
                fields: ["id", "text"],
                data: [["", ""]]
            }),
            editable: false,
            shadow: false,
            mode: 'local',
            triggerAction: 'all',
            maxHeight: 200,
            tpl: '<tpl for="."><div style="height:200px"><div id="'
                + this.treeId + '"></div></div></tpl>',
            selectedClass: '',
            onSelect: Ext.emptyFn,
            valueField: 'id',
            displayField: 'text'
        });

        this.tree = new Coolite.Ext.TreePanel(this.tree);
        this.on('expand', this.onExpand);
        this.tree.on('click', this.onClick, this);
        Ext.ux.ComboTree.superclass.initComponent.apply(this, arguments);
    },
    findExtRecord: function(prop, value) {
        var record;
        if (this.store != null) {
            if (this.store.getCount() > 0) {
                this.store.each(function(r) {
                    if (r.data[prop] == value) {
                        record = r;
                        return false;
                    }
                });
            }
        }
        return record;
    },
    onClick: function(node) {
        if (node.attributes.parameter == 9) {
        } else {
            this.setValue(node.text);
            this.hiddenField.value = node.id;
            this.collapse();
            this.store = new Ext.data.SimpleStore({
                fields: ["id", "text"],
                data: [[node.id, node.text]]
            });
        }
    },
    onExpand: function() {
        if (!this.tree.rendered)
            this.tree.render(this.treeId);
        else this.tree.show();
    }
});
Ext.reg("combotree", Ext.ux.ComboTree);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值