JS Attention
push 返回的是数组增加后的长度!!!
对象名可变
setFieldsValue({ [`bank${index}`]: val });
判断是否空对象
Object.keys(obj);
JSON.stringify(obj) !== "{}";
还有
$.isEmptyObject(data2);
Object.getOwnPropertyNames(data3); // 和Object.keys
类似
关闭标签替换背景图
注意这里的background-size
属性是cover
,也就是让背景图撑满的关键属性。
.exit-btn {
position: fixed;
right: 30px;
top: 30px;
color: white;
background-image: url(../../../../../assets/[email protected]);
&:hover {
background-image: url(../../../../../assets/[email protected]);
}
background-size: cover;
border-radius: 2px;
width: 50px;
height: 49px;
cursor: pointer;
}
获取鼠标点击 DOM 的类名
Event.currentTarget
Event 接口的只读属性 currentTarget 表示的,标识是当事件沿着 DOM 触发时事件的当前目标。它总是指向事件绑定的元素,而 Event.target 则是事件触发的元素。
// 根据当前点击的选色器,取index
const clickWhichOne = (e: any) => {
const clickDom = e.currentTarget;
if (clickDom) {
// 得到当前类名 形如 ChartColorConfig-x
const rightClassName = clickDom.classList[2];
// 转换成数字
const name = rightClassName.split("ChartColorConfig-")[1];
setChooseIndex(name - 0);
}
};
splice 删除与 slice 保留
splice 移除 start 到 end 的词
slice 保留 start 到 end-1 的词
树的修改
// 树的过滤方法
export function treeFilter(tree, func) {
// 使用map复制一下节点,避免修改到原树
return tree
.map((node) => ({ ...node }))
.filter((node) => {
node.children = node.children && treeFilter(node.children, func);
return func(node) || (node.children && node.children.length);
});
}
getGlobalChooseValues;
// 树的寻找
export function treeFind(tree, func, keyWord) {
for (const data of tree) {
if (func(data, keyWord)) return data;
if (data.children) {
const res = treeFind(data.children, func, keyWord);
if (res) return res;
}
}
return null;
}
enum 枚举类型
首字母大写
// 首字母大写 tableTrColor -> TableTrColor
function upperFirstWord(str: string) {
const wordList = str.split("");
const oneWord = wordList[0];
const otherWord = wordList.slice(1);
otherWord.unshift(oneWord.toUpperCase());
return otherWord.join("");
}
掘金更换动头
var ajax = new XMLHttpRequest();
ajax.open("post", "https://juejin.cn/web/user/update/user_info/", true);
ajax.setRequestHeader("content-type", "application/x-www-form-urlencoded");
ajax.send(
"aid=2608&avatar=https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/c38e0574bf6949c28e3c75957a3e3893~tplv-k3u1fbpfcp-jj-mark:345:345:345:345:q75.awebp"
);
ajax.onreadystatechange = function () {
if (ajax.readyState == 4 && ajax.status == 200) {
var c = ajax.responseText;
console.log(c);
}
};
标签:node,const,..,JSNeedAttention,ajax,func,children
From: https://www.cnblogs.com/lepanyou/p/17700029.html