zoukankan      html  css  js  c++  java
  • js 修改属性名和值。并只保留需要的属性

    
    
    result.data =
     [
                {
                  id: "0c4a850086f211eb88ce2e17e48e1195",
                  name: "创新园二期",
                  parentId: "0",
                  iconSkin: "group",
                  isParent: true,
                  orgNode: true,
                  limit: false,
                  polygon: null,
                  lng: null,
                  lat: null,
                  mapImage: null,
                  mobile: null,
                  userId: null,
                  type: 0,
                  code: null,
                  username: null,
                  chief: null,
                  checked: false,
                  nodes: null,
                },
                {
                  id: "0c4a850086f211eb88ce2e17e48e11951111",
                  name: "创新园二期11111",
                  parentId: "0",
                  iconSkin: "group",
                  isParent: true,
                  orgNode: true,
                  limit: false,
                  polygon: null,
                  lng: null,
                  lat: null,
                  mapImage: null,
                  mobile: null,
                  userId: null,
                  type: 0,
                  code: null,
                  username: null,
                  chief: null,
                  checked: false,
                  nodes: null,
                },
              ];


    this
    .treedata = result.data; if (this.treedata && this.treedata.length != 0) {
           

           //删除其他不需要的属性
    this.treedata = this.treedata.map((item, index) => {
              item["title"] = item.name;
    return Object.assign(
                    {},
                    { title: item.title },
                    { loading: false },
                    { children: [] },
                    {
                      id: item.id,
                    }
                  );
                });
              }
              console.log(222, this.treedata);
    得到的结果。
    1. children: Array(0)
    2. id: "0c4a850086f211eb88ce2e17e48e1195"
    3. loading: false
    4. nodeKey: 0
    5. title: "创新园二期"
  • 相关阅读:
    Js特殊字符转义之htmlEscape()方法
    利用Image对象,建立Javascript前台错误日志记录
    html5 实现 文件夹上传
    博客园博客开通了
    js 无刷新文件上传 (兼容IE9 )
    js实现关键词高亮显示 正则匹配
    Python练习六
    Python练习二
    Python练习三
    Python练习四
  • 原文地址:https://www.cnblogs.com/Byme/p/14917609.html
Copyright © 2011-2022 走看看