Ztree's kernel

Source: Internet
Author: User

Kernel of Ztree:
* Structure
(function ($) {
Constants Section
Declare constants because the data is immutable, and if it becomes an object's property, it can easily change the
var ztree_nodecreated = "ztree_nodecreated";
var Ztree_click = "Ztree_click";
var Ztree_rightclick = "Ztree_rightclick";
Methods that plug-in methods provide to external access
$.fn.ztree = function (ztreesetting, ztreenodes) {
Declare a setting
var setting = {
Showline:true,
Checktype: {
"Y": "PS",
"N": "PS"
}
.......
};
Determine if the first argument is passed
if (ztreesetting) {
Replace the user's setting with the value of the original setting
$.extend (setting, ztreesetting);
}
Gets the container ID of the tree
Setting.treeobjid = this.attr ("id");
The container of the tree
Setting.treeobj = this;
Binding Custom Events
Bindtreenodes (setting, this);
By returning a JSON-formatted object in the Ztreeplugin function, this object encapsulates the exposed method (API)
Because the new Ztreeplugin () is returned in the Ztree method, the client does not need to know the details of Ztreeplugin
return new Ztreeplugin (). Init (this);
}
Private methods
function bindtreenodes (setting, Treeobj) {
Declaration of the event
Treeobj.unbind (Ztree_click);
Treeobj.bind (Ztree_click, Function (event, Treeid, TreeNode) {
if ((typeof setting.callback.click) = = "function") Setting.callback.click (event, Treeid, TreeNode);
});
}
function Ztreeplugin () {
return {
Init:function (obj) {
This.container = obj;
this.setting = settings[obj.attr ("id")];
return this;
},
Getselectednode:function () {
return this.setting.curTreeNode;
}
......
};
}
The bounds of private and public methods: As long as the method of writing in the JSON format of the Ztreeplugin return value is the API, no writing is a private method
}) (JQuery);

* Structure Summary:
* Constant part
* Plugin method
Initializing data
Binding events
Call the other method
Exposing APIs
* Methods for exposing APIs
* Private Method

Ztree's kernel

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.