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;
}

posted on 2017-07-10 17:41  Yogurshine  阅读(161)  评论(0编辑  收藏  举报