希望在这里的人可以帮助我弄清楚为什么我收到此错误消息。我一直在使用React Hooks将类组件重构为功能组件,并且在几乎可以检查的每一行上都进行了console.log(),以确保返回的值与原始代码相同。控制台中的所有内容都将匹配,直到我到达异步等待部分为止,这就是控制台指示我遇到“参数不能为null或为空:fieldName”问题的地方。有人有想法么? TIA! (顺便说一句,我知道这里要显示很多代码,但是由于只有在您登录我们的VPN时才可以访问仪表板,因此我不知道有什么更好的方法来显示代码。)
const Categorical = () => {
let viz = useSelector(state => state.fetchDashboard);
const filterSelect = useSelector(state => state.fetchFilterSelect);
let filterApplied = useSelector(state => state.fetchFilter);
const globalFilterTitles = ["Region", "Service Area", "Contract - Cohort"];
const globalFilters = useSelector(state => state.globalFilters)
const dispatch = useDispatch();
const selectedDashboard = useSelector(state => state.selectedDashboard);
const handleChange = (event, key, filterTitle) => {
let selectedValues = filterApplied;
let ind = event.target.value.indexOf("All");
if (filterSelect[key].indexOf("All") > -1) {
if (ind === -1) {
selectedValues[key] = [];
} else {
event.target.value.shift();
selectedValues[key] = event.target.value;
}
} else if (filterSelect[key].indexOf("All") > -1) {
if (ind > -1) {
selectedValues[key] = filterSelect[filterTitle];
} else if (
event.target.value.length + 1 ===
filterSelect[filterTitle].length
) {
selectedValues[key] = filterSelect[filterTitle];
} else {
selectedValues[key] = event.target.value;
}
} else selectedValues[key] = event.target.value;
console.log(selectedValues[key]);
return (
prevState => ({
...prevState,
filterApplied: selectedValues[key]
}),
async function () {
const values =
filterSelect[key].indexOf("All") > -1
? ""
: filterSelect[key];
const fType = values === "" ? "All" : "Replace";
let sheet = await viz
.getWorkbook()
.getActiveSheet()
.getWorksheets()
.get("Index");
sheet
.applyFilterAsync(filterTitle, values, fType)
.then(function () { })
.otherwise(function (err) {
alert(err);
});
let filterNames = {};
let filters = await sheet.getFiltersAsync();
for (let filter in filters) {
if (!isNaN(parseInt(filter))) {
if (
filters[filter].getFilterType() === "categorical" &&
filters[filter].getFieldName() !== "Measure Names" &&
filters[filter].getFieldName() !== "Measure Values" &&
filters[filter].getFieldName().search("_hide") < 0
) {
let filterTitle = filters[filter].getFieldName();
filterNames[filterTitle] = [];
console.log(filterNames[filterTitle])
let len = filters[filter].getAppliedValues().length;
if (
selectedDashboard.categoryForceSelect.indexOf(
filterTitle
) === -1 &&
len !== 0 &&
filterSelect[filterTitle].length - 1 === len
) {
filterNames[filterTitle].push("All");
}
for (let i = 0; i < len; i++) {
if (filters[filter].getAppliedValues()[i].value !== null) {
filterNames[filterTitle].push(
filters[filter].getAppliedValues()[i].value
);
}
}
}
}
}
fetchFilter(filterNames);
if (globalFilterTitles.indexOf(filterTitle) > -1) {
console.log(globalFilterTitles.indexOf(filterTitle));
//take previous value of filters
globalFilters[filterTitle] = filterNames[filterTitle]; // add new values to previous values
console.log(globalFilters);
setGlobalFilters(globalFilters);
} //update state with most recent values.
//Now whenever a new dashboard is requested, the most recent state of global filters will be applied.
}
);
};
我发现sheet.applyFilterAsync(filterTitle)值返回为未定义;一旦我将其更改为在相应位置键入的内容,它就会按预期工作。