Last active
February 18, 2017 08:48
-
-
Save arvidkahl/2cebaece38608b8a143cb55fb385c4b3 to your computer and use it in GitHub Desktop.
jtw-vti-component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add some CSS for indentation | |
.tree-view-item { | |
margin-left: 10px; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vue.component("tree-view-item", Vue.extend({ | |
name: "tree-view-item", | |
props: ["data", "keyType"], | |
methods: { | |
isObject: function(value){ | |
return value.type === 'object'; | |
}, | |
isArray: function(value){ | |
return value.type === 'array'; | |
}, | |
isValue: function(value){ | |
return value.type === 'value'; | |
}, | |
getKey: function(value){ | |
if (_.isInteger(value.key)) { | |
return value.key; | |
} else { | |
return "\""+ value.key + "\""; | |
} | |
}, | |
getValue: function(value){ | |
if (_.isNumber(value.value)) { | |
return value.value | |
} | |
if (_.isNull(value.value)) { | |
return "null" | |
} | |
if (_.isString(value.value)) {} | |
return "\""+value.value+"\""; | |
}, | |
isRootObject: function(value){ | |
return value.isRoot; | |
} | |
}, | |
template:` | |
<div class="tree-view-item"> | |
<div v-if="isObject(data)"> | |
<div class="tree-view-item-grouping"> | |
<span v-if="!isRootObject(data)" class="tree-view-item-key">{{getKey(data)}}</span> | |
<span v-if="!isRootObject(data)" class="tree-view-item-divider">:</span> | |
{ | |
</div> | |
<tree-view-item v-for="child in data.children" :data="child"></tree-view-item> | |
<div class="tree-view-item-grouping">}</div> | |
</div> | |
<div v-if="isArray(data)"> | |
<div class="tree-view-item-grouping"> | |
<span class="tree-view-item-key">{{getKey(data)}} | |
<span class="tree-view-item-divider">:</span> | |
[ | |
</div> | |
<tree-view-item v-for="child in data.children" :data="child"></tree-view-item> | |
<div class="tree-view-item-grouping">]</div> | |
</div> | |
<div v-if="isValue(data)"> | |
<span class="tree-view-item-key">{{getKey(data)}}</span> | |
<span class="tree-view-item-divider">:</span> | |
<span class="tree-view-item-value">{{getValue(data)}} | |
</div> | |
</div> | |
` | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment