求一个JS树控件 asp.net中使用 每个节点右边有按钮的那种

JavaScript07

求一个JS树控件 asp.net中使用 每个节点右边有按钮的那种,第1张

1.1.创建一棵树

2.使用如下方式

3.var tree=new JsTree('DivId')

4.说明,html的body里面必须事先有id为'DivId'的层。

5.这棵树将在此渲染。

6.2.创建节点

7.var node1=new JsNode("nodeid")

8.树在以一始不能渲染,要渲染必须设置它的根

9.用下面的语法:

10.tree.setRoot(node1)// 这样就将node1设置成了它的根,div已经被渲染。

11.以后只要按照一棵树的形态加入节点就可以了。

12.如下所示:

13.var tree=new JsTree("div1")

14.var root=new JsNode("root")//root为节点的ID

15.root.text="刘u22791 "//设置节点显示的文本,也可以是超链接,html代码 等,要是不设置这个属性,树就显示它的Id

16.root.hasCheckBox=true//设置了这个属性以后,节点就还有一个CheckBox

17.tree.setRoot(root)//根节点的属性设置好以后才能将它给树对象

18.var n1=new JsNode("张u-26402 ")

19.var n2=new JsNode("关u32701 ")

20.var n3=new JsNode("赵u20113 ")

21.var n4=new JsNode("将")

22.var n5=new JsNode("将")

23.var n6=new JsNode("兵")

24.var n7=new JsNode("兵")

25.var n8=new JsNode("兵")

26.root.add(n1)

27.root.add(n2)

28.n2.add(n4)//这些方法,就将1个节点添加它的子节点

29.n2.add(n5)

30.n4.add(n6)

31.n4.add(n7)

32.n1.add(n8)

33.root.add(n3)

34.这样就能动态的构建树了

35.

36.下面提供一些全局API,直接使用这些方法

37.getAllTrees() 获得所有的树对象,一个html上面可能有很多树

38.getTreeByDivId(divid) 通过树注册的divId获得这棵树

39.getNodeById(nid) //通过节点Id,从所有的树中查找一个节点对象,找到就返回,找不到返回null

40.checkCbo(node) 选中这个节点的CheckBox

41.checkCboById(nodeid) 通过节点的Id来选中起CheckBox

42.cancelCbo(node) 取消对Checkbox的选中

43.cancelCboById(nid) 通过节点id取消对Checkbox的选中

44.closeThis(node) 关闭节点

45.openThis(node) 打开

46.closeNodeById(nid) 通过节点Id关闭

47.openNodeById(nid) 通过Id节点打开

48.

49.下面是树对象的API

50.getById(key) // getNodeById

51.removeNode(node) // 核心方法

52.getCheckedNodesXml() /// 对外 API

53.getCheckedNodes() /// 对外 API

54.showText()//////对外 API

55.showId()//对外 API

56.上面的方法 如此使用 var arr=tree.getCheckedNodes()这样就得到了所有的选中节点。

jsp从mysql数据库读取数据,并填充到树形结构菜单并展现出来的实现方法:

1、引入jquery.treeview.js树控件

<script type="text/javascript" src="jquery/easyui/jquery.min.js"></script>

 <script type="text/javascript" src="jquery/easyui/jquery.easyui.min.js"></script>

2、jsp页面中获取后台mysql数据,并传到jsp页面来

<% 

// 数据库的名字

String dbName = "zap"

// 登录数据库的用户名

String username = "sa"

// 登录数据库的密码

String password = "123"

// 数据库的IP地址,本机可以用 localhost 或者 127.0.0.1

String host = "127.0.0.1"

// 数据库的端口,一般不会修改,默认为1433

int port = 1433

String connectionUrl = "jdbc:sqlserver://" + host + ":" + port + "databaseName=" + dbName + "user=" + username

+ "password=" + password

//

//声明需要使用的资源 

// 数据库连接,记得用完了一定要关闭

Connection con = null

// Statement 记得用完了一定要关闭

Statement stmt = null

// 结果集,记得用完了一定要关闭

ResultSet rs = null

try {

// 注册驱动 

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver")

// 获得一个数据库连接

con = DriverManager.getConnection(connectionUrl)

String SQL = "SELECT * from note"

// 创建查询

stmt = con.createStatement()

// 执行查询,拿到结果集

rs = stmt.executeQuery(SQL)

while (rs.next()) {

%>

<tr>

3、填充树形菜单:

{

 id          : "string" // will be autogenerated if omitted

 text        : "string" // node text

 icon        : "string" // string for custom

 state       : {

   opened    : boolean  // is the node open

   disabled  : boolean  // is the node disabled

   selected  : boolean  // is the node selected

 },

 children    : []  // array of strings or objects

 li_attr     : {}  // attributes for the generated LI node

 a_attr      : {}  // attributes for the generated A node

}

$('#tree').jstree({

   'core' : {

       'data' : function (obj, cb) {

           cb.call(this,

             ['Root 1', 'Root 2'])

       }

   }})

从可见的行列表中提取部分: NSArray *indexPathsForVisibleRows = [tableView indexPathsForVisibleRows]

NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet]

for ( NSIndexPath *indexPath in indexPathsForVisibleRows ) {

[indexSet addIndex:indexPath.section]

}

NSLog(@"indexSet %@",indexSet)

// indexSet <NSMutableIndexSet: 0x11a5c190>[number of indexes: 5 (in 1 ranges