如何解决在这种情况下,我正在创建一个简单的计数器,为什么在内部而不在外部工作却感到困惑,为什么我不能在函数外部输出?
为什么我不能在此函数外部输出,为什么必须在函数内部?
Map<String,List<Person>> grupPerson() {
Map<String,List<Person>> tempMap = {};
for (var i = 0; i < listAlphabet.length; i++) {
final result = listPerson
.where((person) => person.fullName.toLowerCase().startsWith(listAlphabet[i].name))
.toList();
for (var j = 0; j < result.length; j++) {
final original = tempMap[listAlphabet[i].name];
if (original == null) {
tempMap[listAlphabet[i].name] = [result[j]];
} else {
tempMap[listAlphabet[i].name] = [...original,result[j]];
}
}
}
return tempMap;
}
/// Result
{a: [Instance of 'Person'],h: [Instance of 'Person'],s: [Instance of 'Person'],z: [Instance of 'Person',Instance of 'Person',Instance of 'Person']}
解决方法
因为如果它是您在问题中所显示的位置,则该值为0
。该代码在页面加载时立即运行,而无需等待调用countJar
的等待。现在,它要运行到调用countJar
为止。
如果是指您尝试将0
放在其中时甚至看不到id="demo"
,那是因为function scrollShowHideHeader() {
let position = $(window).scrollTop();
let prevPageHeight = $('#site-content').outerHeight();
$(window).on('scroll',() => {
let scroll = $(window).scrollTop();
let lastPageHeight = $('#site-content').outerHeight();
if (lastPageHeight === prevPageHeight) {
if (scroll > position) {
$('#site-header').addClass('is-hidden');
} else {
$('#site-header').removeClass('is-hidden');
}
position = scroll;
}
prevPageHeight = lastPageHeight;
});
}
元素尚不存在。如果这就是您的意思,请this question's answers适用。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。