您好,请参考 如下代码
- // create the tree
- var tree = new wijmo.nav.TreeView('#theTree', {
- itemsSource: getData(),
- displayMemberPath: 'header',
- childItemsPath: 'items',
- showCheckboxes: true
- });
- // initialize the checked items
- tree.checkedItems = [
- findItem(tree, 'Apple'),
- findItem(tree, 'Motorola'),
- findItem(tree, 'Samsung'),
- findItem(tree, 'Shopkins'),
- findItem(tree, 'Crayola')
- ]
- // find a data item in the tree based on the displayMemberPath value
- function findItem(tree, value, items) {
- if (!items) {
- items = tree.itemsSource;
- }
- for (var i = 0; i < items.length; i++) {
- var item = items[i];
- if (item[tree.displayMemberPath] == value) {
- return item;
- }
- var childItems = item[tree.childItemsPath];
- if (childItems) {
- var child = findItem(tree, value, childItems);
- if (child) {
- return child;
- }
- }
- }
- return null;
- }
- // get the tree data
- function getData() {
- return [{
- header: 'Electronics',
- img: 'resources/electronics.png',
- items: [{
- header: 'Trimmers/Shavers'
- },
- {
- header: 'Tablets'
- },
- {
- header: 'Phones',
- img: 'resources/phones.png',
- items: [{
- header: 'Apple'
- },
- {
- header: 'Motorola',
- newItem: true
- },
- {
- header: 'Nokia'
- },
- {
- header: 'Samsung'
- }
- ]
- },
- {
- header: 'Speakers',
- newItem: true
- },
- {
- header: 'Monitors'
- }
- ]
- },
- {
- header: 'Toys',
- img: 'resources/toys.png',
- items: [{
- header: 'Shopkins'
- },
- {
- header: 'Train Sets'
- },
- {
- header: 'Science Kit',
- newItem: true
- },
- {
- header: 'Play-Doh'
- },
- {
- header: 'Crayola'
- }
- ]
- },
- {
- header: 'Home',
- img: 'resources/home.png',
- items: [{
- header: 'Coffee Maker'
- },
- {
- header: 'Breadmaker',
- newItem: true
- },
- {
- header: 'Solar Panel',
- newItem: true
- },
- {
- header: 'Work Table'
- },
- {
- header: 'Propane Grill'
- }
- ]
- }
- ];
复制代码 |