console
Vue.component('item', {
template: '#item_template',
props: {
model: Object
},
data: function () {
return {
id: '',
index: new Number,
}
},
computed: {
isFolder: function () {
return this.model.children &&
this.model.children.length
}
},
watch: {
index(Value,oldValue) {
this.model.select_index = Value;
this.model.children.forEach(v=>{
v.select_index = undefined;
})
this.id = Value
this.toggle(this.index)
this.model.new_NodeA = ""
this.new_Node = ""
},
},
methods: {
toggle(index) {
},
},
})
new Vue({
el: '#app',
data: {
treeData: [],
knows: 0,
mastery_degree: [],
json:[{"id":"1","name":"几何初步和三角形1","father":"0","children":[{"id":"2","children_A":"[3,7","father":"1","name":"几何初步","children":[{"id":"3","children_A":"[4,5,6","father":"2","name":"角","children":[{"id":"4","children_A":"0","father":"3","name":"角的定义"},{"id":"5","children_A":"0","father":"3","name":"角的分类"},{"id":"6","children_A":"0","father":"3","name":"角的计算和比较"}]},{"id":"7","children_A":"[8,9,17","father":"2","name":"线","children":[{"id":"8","children_A":"0","father":"7","name":"直线、射线、线段的定义"},{"id":"9","children_A":"[10,13","father":"7","name":"相交线","children":[{"id":"10","children_A":"[11,12","father":"9","name":"两条直线相交","children":[{"id":"11","children_A":"0","father":"10","name":"对顶角"},{"id":"12","children_A":"0","father":"10","name":"两直线垂直及其性质"}]},{"id":"13","children_A":"[14,15,16","father":"9","name":"两条直线被第三条直线所截","children":[{"id":"14","children_A":"0","father":"13","name":"内错角"},{"id":"15","children_A":"0","father":"13","name":"同位角"},{"id":"16","children_A":"0","father":"13","name":"同旁内角"}]}]},{"id":"17","children_A":"[18,19","father":"7","name":"平行线","children":[{"id":"18","children_A":"0","father":"17","name":"平行线的性质和判断"},{"id":"19","children_A":"[20","father":"17","name":"平行公理及推理","children":[{"id":"20","children_A":"0","father":"19","name":"分支主题"}]}]}]}]},{"id":"21","children_A":"[22,23,32","father":"1","name":"三角形","children":[{"id":"22","children_A":"0","father":"21","name":"三角形相关定义和概念"},{"id":"23","children_A":"[24,28","father":"21","name":"三角形分类","children":[{"id":"24","children_A":"[25,26,27","father":"23","name":"按角分类","children":[{"id":"25","children_A":"0","father":"24","name":"锐角三角形"},{"id":"26","children_A":"0","father":"24","name":"直角三角形"},{"id":"27","children_A":"0","father":"24","name":"钝角三角形"}]},{"id":"28","children_A":"[29,30,31","father":"23","name":"按边分类","children":[{"id":"29","children_A":"0","father":"28","name":"等边三角形"},{"id":"30","children_A":"0","father":"28","name":"等腰三角形"},{"id":"31","children_A":"0","father":"28","name":"普通三角形"}]}]},{"id":"32","children_A":"[33,34","father":"21","name":"三角形得性质","children":[{"id":"33","children_A":"0","father":"32","name":"三角形三边关系"},{"id":"34","children_A":"0","father":"32","name":"三角形的内外角关系"}]}]}],"children_A":"[2,21"}],
},
methods: {
knows_add() {
this.treeData.push({
id: -1,
name:"目录",
children: JSON.parse(JSON.stringify(this.json)) || [],
uuid: Math.random().toString()
})
this.knows += 1
},
knows_delete(index) {
console.log(index)
this.treeData.splice(index, 1)
this.knows -= 1
this.mastery_degree.splice(index, 1)
},
}
})
<div id="app">
<div v-for="(model,index) in treeData"
:key="model.uuid">
<div style="margin-left:30px;">
<nobr>
<h3>{{index + 1}}选择知识点</h3>
<button class="login-button" @click="knows_delete(index)">-</button>
</nobr>
<item class="item"
v-model="treeData[index]"
:model="treeData[index]" ></item>
<h3>掌握级别</h3>
<select class="search" v-model="mastery_degree[index]">
<option :value='1'>掌握</option>
<option :value='2'>部分掌握</option>
<option :value='3'>未掌握</option>
</select>
<br /><br />
</div>
</div>
<button class="login-button" @click="knows_add">增加</button>
</div>
<script type="text/x-template" id="item_template">
<div>
<select @input="index = $event.target.value" :value="model.select_index" class="search">
<option :value="model.id" v-for="(model, index) in model.children">{{model.name}}</option>
</select>
<br>
<div>
<item class="item"
v-for="(model, index) in model.children"
:key="index"
v-if="model.id == id && model.id !== 0 && model.children != undefined"
:model="model">
</item>
</div>
</div>
</script>