Tree: setCurrentKey cancels highlight when param is null (#11205)

pull/11214/head
杨奕 2018-05-17 13:30:58 +08:00 committed by GitHub
parent b79a98c7e0
commit e809720ce4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 4 deletions

View File

@ -1212,7 +1212,7 @@ You can drag and drop Tree nodes by adding a `draggable` attribute.
| getHalfCheckedKeys | If the node can be selected (`show-checkbox` is `true`), it returns the currently half selected array of node's keys | - | | getHalfCheckedKeys | If the node can be selected (`show-checkbox` is `true`), it returns the currently half selected array of node's keys | - |
| getCurrentKey | return the highlight node's key (null if no node is highlighted) | — | | getCurrentKey | return the highlight node's key (null if no node is highlighted) | — |
| getCurrentNode | return the highlight node (null if no node is highlighted) | — | | getCurrentNode | return the highlight node (null if no node is highlighted) | — |
| setCurrentKey | set highlighted node by key, only works when `node-key` is assigned | (key) the node's key to be highlighted | | setCurrentKey | set highlighted node by key, only works when `node-key` is assigned | (key) the node's key to be highlighted. If `null`, cancel the currently highlighted node |
| setCurrentNode | set highlighted node, only works when `node-key` is assigned | (node) the node to be highlighted | | setCurrentNode | set highlighted node, only works when `node-key` is assigned | (node) the node to be highlighted |
| getNode | get node by data or key | (data) the node's data or key | | getNode | get node by data or key | (data) the node's data or key |
| remove | remove a node | (data) the node's data or node to be deleted | | remove | remove a node | (data) the node's data or node to be deleted |

View File

@ -1210,7 +1210,7 @@ You can drag and drop Tree nodes by adding a `draggable` attribute.
| getHalfCheckedKeys | Si el nodo puede ser seleccionado (`show-checkbox` es `true`), devuelve la mitad de la matriz de claves del nodo actualmente seleccionado. | - | | getHalfCheckedKeys | Si el nodo puede ser seleccionado (`show-checkbox` es `true`), devuelve la mitad de la matriz de claves del nodo actualmente seleccionado. | - |
| getCurrentKey | devuelve la clave del nodo resaltado actualmente (null si no hay ninguno) | — | | getCurrentKey | devuelve la clave del nodo resaltado actualmente (null si no hay ninguno) | — |
| getCurrentNode | devuelve el nodo resaltado (null si no hay ninguno) | — | | getCurrentNode | devuelve el nodo resaltado (null si no hay ninguno) | — |
| setCurrentKey | establece el nodo resaltado por la clave, solo funciona si `node-key` está asignado | (key) la clave del nodo a ser resaltado | | setCurrentKey | establece el nodo resaltado por la clave, solo funciona si `node-key` está asignado | (key) la clave del nodo a ser resaltado. If `null`, cancel the currently highlighted node |
| setCurrentNode | establece el nodo resaltado, solo funciona si `node-key` está asignado | (node) nodo a ser resaltado | | setCurrentNode | establece el nodo resaltado, solo funciona si `node-key` está asignado | (node) nodo a ser resaltado |
| getNode | devuelve el nodo por el dato o la clave | (data) los datos o clave del nodo | | getNode | devuelve el nodo por el dato o la clave | (data) los datos o clave del nodo |
| remove | elimina un nodo | (data) los datos del nodo o nodo a borrar | | remove | elimina un nodo | (data) los datos del nodo o nodo a borrar |

View File

@ -1233,7 +1233,7 @@
| getHalfCheckedKeys | 若节点可被选择(即 `show-checkbox``true`),则返回目前半选中的节点的 key 所组成的数组 | - | | getHalfCheckedKeys | 若节点可被选择(即 `show-checkbox``true`),则返回目前半选中的节点的 key 所组成的数组 | - |
| getCurrentKey | 获取当前被选中节点的 key使用此方法必须设置 node-key 属性,若没有节点被选中则返回 null | — | | getCurrentKey | 获取当前被选中节点的 key使用此方法必须设置 node-key 属性,若没有节点被选中则返回 null | — |
| getCurrentNode | 获取当前被选中节点的 node若没有节点被选中则返回 null | — | | getCurrentNode | 获取当前被选中节点的 node若没有节点被选中则返回 null | — |
| setCurrentKey | 通过 key 设置某个节点的当前选中状态,使用此方法必须设置 node-key 属性 | (key) 待被选节点的 key | | setCurrentKey | 通过 key 设置某个节点的当前选中状态,使用此方法必须设置 node-key 属性 | (key) 待被选节点的 key,若为 null 则取消当前高亮的节点 |
| setCurrentNode | 通过 node 设置某个节点的当前选中状态,使用此方法必须设置 node-key 属性 | (node) 待被选节点的 node | | setCurrentNode | 通过 node 设置某个节点的当前选中状态,使用此方法必须设置 node-key 属性 | (node) 待被选节点的 node |
| getNode | 根据 data 或者 key 拿到 Tree 组件中的 node | (data) 要获得 node 的 key 或者 data | | getNode | 根据 data 或者 key 拿到 Tree 组件中的 node | (data) 要获得 node 的 key 或者 data |
| remove | 删除 Tree 中的一个节点 | (data) 要删除的节点的 data、key 或者 node | | remove | 删除 Tree 中的一个节点 | (data) 要删除的节点的 data、key 或者 node |

View File

@ -322,6 +322,10 @@ export default class TreeStore {
} }
setCurrentNodeKey(key) { setCurrentNodeKey(key) {
if (key === null) {
this.currentNode = null;
return;
}
const node = this.getNode(key); const node = this.getNode(key);
if (node) { if (node) {
this.currentNode = node; this.currentNode = node;

View File

@ -448,9 +448,14 @@ describe('Tree', () => {
tree.setCurrentKey(111); tree.setCurrentKey(111);
vm.$nextTick(() => { vm.$nextTick(() => {
expect(tree.store.currentNode.data.id).to.equal(111); expect(tree.store.currentNode.data.id).to.equal(111);
// cancel highlight
tree.setCurrentKey(null);
vm.$nextTick(() => {
expect(tree.store.currentNode).to.equal(null);
done(); done();
}); });
}); });
});
it('setCurrentNode', (done) => { it('setCurrentNode', (done) => {
vm = getTreeVm(':props="defaultProps" show-checkbox node-key="id"'); vm = getTreeVm(':props="defaultProps" show-checkbox node-key="id"');