js方法(提取汉字,数组去重,获取树节点)

//提取汉字和逗号
function GetChinese(strValue) {
	if (strValue != null && strValue != "") {
		var reg = /[\u4e00-\u9fa5]|,|[A-Z]/g;
		return strValue.match(reg).join("");
	} else
		return "";
}
//去重方法
Array.prototype.delRepeat = function () {
	var temp = {},
		len = this.length;
	for (var i = 0; i < len; i++) {
		var tmp = this[i];
		if (!temp.hasOwnProperty(tmp)) { //hasOwnProperty用来判断一个对象是否有你给出名称的属性或对象
			temp[this[i]] = "yes";
		}
	}
	len = 0;
	var tempArr = [];
	for (var i in temp) {
		tempArr[len++] = i;
	}
	return tempArr;
}
/**
 * 获取所有的直接点的id
 * @param curNode
 * @returns
 */
function getAllChildrenNodeId(curNode, nodeIds) {

	if (curNode.isParent) {
		var childrenNodes = curNode.children;
		if (childrenNodes) {
			for (var i = 0; i < childrenNodes.length; i++) {
				nodeIds += ",'" + childrenNodes[i].id + "'";
				console.info(nodeIds);
				nodeIds = getAllChildrenNodeId(childrenNodes[i], nodeIds);
			}
		}
	}
	return nodeIds;
}

 

你可能感兴趣的:(js)