数组
1、数组排序:
var list= [40, 100, 1, 5, 25, 10];
list.sort(function(a, b){return b-a}); // 按降序对数组中的数字进行排序
list.sort(function(a, b){return a-b}); // 按升序对数组中的数字进行排序
2、根据数组项中的对象的key的值大小来排序数组:
let list = [{value: 1,name:'测试'},{value: 3,name:'测试'},{value: 2,name:'测试'}]
list = list.sort(compare("value"));
function compare(property) {
return function (a, b) {
var value1 = a[property];
var value2 = b[property];
return value2 - value1;
};
}
console.log(list)
// 或者
let list = [{value: 1,name:'测试'},{value: 3,name:'测试'},{value: 2,name:'测试'}]
list = list.sort(function(a,b){return b['value'] - a['value']});
console.log(list)
filter过滤取数组项
let TabList = [{name: '1', type: 2},{name: '2', type: 3}]
let index = TabList.filter(p => p.type == 1);
遍历数组下标
let index;
let type = 2;
let TabList = [{name: '1', type: 2},{name: '2', type: 3}]
TabList.forEach((item, val) => {
if (type === item.type) {
index = val
}
});
VUE强制重新渲染
下拉框等值改变时,页面元素未重新渲染,可尝试使用以下强制重新渲染解决
@change="$forceUpdate()"
查询产生滚动条元素
原文:https://blog.csdn.net/qq_42931285/article/details/128091050
js如何快速找到是哪个元素产生滚动条的
function findscroller(element){
element.onscroll=function () {
console.log(element)
}
Array.from(element.children).forEach(findscroller)
}
findscroller(document.body)
个人学习记录