• Code Review


    1.判断两个空数组相等

    (Array.isArray(oldValue) && Array.isArray(newValue)) {
    if (Utility.ArrayIsEqual(oldValue, newValue)) {
    continue;
    }
    }

    static ArrayIsEqual(value1: any[], value2: any[]): boolean {
    if (!value1)
    return false;
    if (value2.length != value1.length)
    return false;
    for (var i = 0, l = value2.length; i < l; i++) {
    // Check if we have nested arrays
    if (value2[i] instanceof Array && value1[i] instanceof Array) {
    // recurse into the nested arrays
    if (!value2[i].equals(value1[i]))
    return false;
    }
    else if (value2[i] != value1[i]) {
    // Warning - two different object instances will never be equal: {x:20} != {x:20}
    return false;
    }
    }
    return true;
    }
    }

    2.

    let value = args.data;
    let text = ""
    for (let i = 0; i < value.length; i++) {
    text += "<span>" + value[i].name + "</span>";
    text += "<br>";
    }

    args.text = text;
    this._selectedUsers = value.slice();

    重构:

    let value: any[] = args.data;
    let text = "";

    let textArray = value.map(r => {
    return "<span>" + r.name + "</span>";
    });
    text = textArray.join("<br />");
    args.text = text;
    this._selectedUsers = value.slice();

    3.Text value不一致

    case KType.GROUP_SELECT: {
    let f = field as SelectUserFieldInfo;
    let nameArr = [];
    let valueArr = value as IGroupOrgObj[];
    for (let i = 0; i < valueArr.length; i++) {
    nameArr.push(valueArr[i].name);
    }
    value = nameArr.join(";");
    break;
    }

    case KType.GROUP_SELECT: {
    let f = field as SelectUserFieldInfo;
    //let nameArr = [];
    //let valueArr = value as IGroupOrgObj[];
    //for (let i = 0; i < valueArr.length; i++) {
    // nameArr.push({
    // name: valueArr[i].name,
    // code: valueArr[i].code
    // });
    //}
    //value = nameArr.slice();
    break;
    }

  • 相关阅读:
    禁止鼠标多次点击选中div中的文字
    深入浅出 Nodejs 学习笔记 1
    svn 树冲突
    nodejs 按行读取 readline
    git版本控制器的基本使用
    规范javascript书写
    media query
    软件工程
    The sixth day
    The fifth day
  • 原文地址:https://www.cnblogs.com/Yogurshine/p/7146949.html
Copyright © 2020-2023  润新知