modify: 搜索demo

This commit is contained in:
wh 2017-10-23 13:31:47 +08:00
parent d7cb124f94
commit dc5a252480
2 changed files with 40 additions and 28 deletions

View File

@ -1,12 +1,14 @@
/** /**
* *
* @title Tree可搜索事例 * @title Tree可搜索事例
* @description * @description
* *
*/ */
import React, { Component } from 'react'; import React, {
Component
} from 'react';
import FormControl from 'bee-form-control'; import FormControl from 'bee-form-control';
import Tree from '../../src'; import Tree from '../../src';
@ -22,7 +24,10 @@ const generateData = (_level, _preKey, _tns) => {
const children = []; const children = [];
for (let i = 0; i < x; i++) { for (let i = 0; i < x; i++) {
const key = `${preKey}-${i}`; const key = `${preKey}-${i}`;
tns.push({ title: key, key }); tns.push({
title: key,
key
});
if (i < y) { if (i < y) {
children.push(key); children.push(key);
} }
@ -45,7 +50,10 @@ const generateList = (data) => {
for (let i = 0; i < data.length; i++) { for (let i = 0; i < data.length; i++) {
const node = data[i]; const node = data[i];
const key = node.key; const key = node.key;
dataList.push({ key, title: key }); dataList.push({
key,
title: key
});
if (node.children) { if (node.children) {
generateList(node.children, node.key); generateList(node.children, node.key);
} }
@ -84,8 +92,8 @@ class Demo4 extends Component {
autoExpandParent: false, autoExpandParent: false,
}); });
} }
onChange = (e) => { onChange = (value) => {
const value = e.target.value; // const value = e.target.value;
const expandedKeys = []; const expandedKeys = [];
dataList.forEach((item) => { dataList.forEach((item) => {
if (item.key.indexOf(value) > -1) { if (item.key.indexOf(value) > -1) {
@ -105,7 +113,11 @@ class Demo4 extends Component {
}); });
} }
render() { render() {
const { searchValue, expandedKeys, autoExpandParent } = this.state; const {
searchValue,
expandedKeys,
autoExpandParent
} = this.state;
const loop = data => data.map((item) => { const loop = data => data.map((item) => {
const index = item.key.search(searchValue); const index = item.key.search(searchValue);
const beforeStr = item.key.substr(0, index); const beforeStr = item.key.substr(0, index);

File diff suppressed because one or more lines are too long