如何删除特定的某项?

依依雨柔
  • 233

对于传进的id,如何找到organguid,并删除与传入id相等的项及其children?

treeData: [{
  id: '0',
  organguid: '',
  parentguid: '',
  organname: '图书分类',
  organtype: '0',
  organDesc: '',
  children: []
}],
defaultProps: {
  children: 'children',
  label: 'organname'
}


this.treeData[0].children = [{
            organguid: '1',
            parentguid: '0',
            organtype: '1',
            organDesc: '',
            organname: '中国文学',
            children: [{
              organguid: '4',
              parentguid: '1',
              organtype: '2',
              organDesc: '',
              organname: '近代文学'
            }, {
              organguid: '5',
              parentguid: '1',
              organtype: '2',
              organDesc: '',
              organname: '古典文学'
            }]
          },
          {
            organguid: '2',
            parentguid: '0',
            organtype: '1',
            organDesc: '',
            organname: '小说',
            children: [{
              organguid: '6',
              parentguid: '2',
              organtype: '2',
              organDesc: '',
              organname: '经典小说'
            }, {
              organguid: '7',
              parentguid: '2',
              organtype: '2',
              organDesc: '',
              organname: '古侠小说'
            }]
          }, {
            organguid: '3',
            parentguid: '0',
            organtype: '1',
            organDesc: '',
            organname: '辅导资料',
            children: [{
              organguid: '8',
              parentguid: '3',
              organtype: '2',
              organDesc: '',
              organname: '高考'
            }, {
              organguid: '9',
              parentguid: '3',
              organtype: '2',
              organDesc: '',
              organname: '出国考试',
              children: [{
                organguid: '10',
                parentguid: '9',
                organtype: '3',
                organDesc: '',
                organname: '雅思'
              }, {
                organguid: '11',
                parentguid: '9',
                organtype: '3',
                organDesc: '',
                organname: '托福'
              }, {
                organguid: '12',
                parentguid: '9',
                organtype: '3',
                organDesc: '',
                organname: 'GRE'
              }]
            }]
          }]
回复
阅读 1.1k
1 个回答
牛书书
  • 10k

就是修改树节点数据,视图自动更新,一般的组件都会提供接口可以进行修改的。
用过element-ui以及iView的树组件,不甚满意,自己写了一个树组件,可以了解一下:https://github.com/Lushenggan...
项目里有例子可以看看,源码也很简单,也可以通过npm或者yarn安装组件到项目中使用,样式高度可控。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏