Skip to content

Commit

Permalink
#90 Property names ignored on async load children
Browse files Browse the repository at this point in the history
  • Loading branch information
amsik committed Dec 19, 2018
1 parent dacdc88 commit be1d512
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
25 changes: 24 additions & 1 deletion demo/pages/async.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@
<tree :options="fetchExample1" :data="treeData1" />
</div>
</div>

<div class="example">
<div class="example-description">
Prop names
</div>
<div class="example-tree">
<tree :options="fetchExample2" />
</div>
</div>
</div>
</div>

Expand Down Expand Up @@ -104,8 +113,22 @@
// return Promise object
return fetch(`/assets/data/fetch0/data-${node.id}.json`).then(r => r.json()).catch(e => console.log(e))
}
}
},

fetchExample2: {
propertyNames: {
text: 'name',
},
fetchData: node => {
return new Promise((resolve, reject) => {
resolve({
id: 1,
name: 'test',
isBatch: true,
});
})
}
}
})
})
</script>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "liquor-tree",
"description": "A Vue.js tree component.",
"version": "0.2.46",
"version": "0.2.47",
"author": "Kostiantyn <[email protected]>",
"library": "LiquorTree",
"homepage": "https://amsik.github.io/liquor-tree/",
Expand Down
14 changes: 9 additions & 5 deletions src/lib/Tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,23 @@ export default class Tree {
})
}

fetch (node) {
fetch (node, parseData) {
let result = this.options.fetchData(node)

if (!result.then) {
result = get(result)
.catch(this.options.onFetchError)
}

result
.then(data => data && this.parse(data, this.options.modelParse))
.catch(this.options.onFetchError)
if (false === parseData) {
return result
}

return result
.then(data => {
return this.parse(data, this.options.modelParse)
})
.catch(this.options.onFetchError)
}

fetchInitData () {
Expand All @@ -221,7 +225,7 @@ export default class Tree {
name: 'root'
}

return this.fetch(node)
return this.fetch(node, false)
}

setModel (data) {
Expand Down

0 comments on commit be1d512

Please sign in to comment.