Tree: add defaultExpandKeys & defaultCheckedKeys. (#1088)

This commit is contained in:
FuryBean
2016-11-16 15:35:46 +08:00
committed by cinwell.li
parent af4bca8abe
commit 5203280af1
12 changed files with 385 additions and 97 deletions

View File

@@ -6,11 +6,15 @@
:props="props"
:render-content="renderContent">
</el-tree-node>
<div class="el-tree__empty-block" v-if="!tree.root.childNodes || tree.root.childNodes.length === 0">
<span class="el-tree__empty-text">{{ emptyText }}</span>
</div>
</div>
</template>
<script type="text/ecmascript-6">
import Tree from './model/tree';
import { t } from 'element-ui/src/locale';
export default {
name: 'el-tree',
@@ -19,6 +23,19 @@
data: {
type: Array
},
emptyText: {
type: String,
default: t('el.tree.emptyText')
},
nodeKey: String,
checkStrictly: Boolean,
defaultExpandAll: Boolean,
autoExpandParent: {
type: Boolean,
default: true
},
defaultCheckedKeys: Array,
defaultExpandedKeys: Array,
renderContent: Function,
showCheckbox: {
type: Boolean,
@@ -38,19 +55,23 @@
default: false
},
highlightCurrent: Boolean,
load: {
type: Function
}
load: Function
},
created() {
this.$isTree = true;
this.tree = new Tree({
key: this.nodeKey,
data: this.data,
lazy: this.lazy,
props: this.props,
load: this.load
load: this.load,
checkStrictly: this.checkStrictly,
defaultCheckedKeys: this.defaultCheckedKeys,
defaultExpandedKeys: this.defaultExpandedKeys,
autoExpandParent: this.autoExpandParent,
defaultExpandAll: this.defaultExpandAll
});
},
@@ -78,13 +99,20 @@
watch: {
data(newVal) {
this.tree.root.setData(newVal);
this.tree.setData(newVal);
},
defaultCheckedKeys(newVal) {
this.tree.setDefaultCheckedKey(newVal);
}
},
methods: {
getCheckedNodes(leafOnly) {
return this.tree.getCheckedNodes(leafOnly);
},
setCheckedNodes(nodes) {
if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in setCheckedNodes');
this.tree.setCheckedNodes(nodes);
}
}
};