reactjs 应为赋值或函数调用,但看到的却是表达式

iecba09b  于 2023-06-22  发布在  React
关注(0)|答案(2)|浏览(117)

我正在修复这方面的bug &我不断得到“期待一个赋值或函数调用,而不是看到一个表达式”错误。

const CHARTID = "chart_id";
const FIELDID = "field_id";
const TIMEFILTERVALUE= "time_filter_input";
const TIMEFILTERUNIT = "time_filter_type"
const UNITFILTER = "unit_filter";

const constrcutFilterOptions = (field_id, chartId, timeFilterType, timeFilterUnit, unit)=> {

  var filterObj = {};
  !_.isNil(field_id) ? filterObj[FIELDID] = field_id : null;
  !_.isNil(chartId) ? filterObj[CHARTID] = chartId : null;
  !_.isNil(timeFilterType) ? filterObj[TIMEFILTERUNIT] = timeFilterType : null;
  !_.isNil(timeFilterUnit) ? filterObj[TIMEFILTERVALUE] = timeFilterUnit : null;
  !_.isNil(unit) ? filterObj[UNITFILTER] = unit : null;

  return filterObj;

}
eyh26e7m

eyh26e7m1#

你应该在三元条件之前写作业:

const CHARTID = "chart_id";
const FIELDID = "field_id";
const TIMEFILTERVALUE= "time_filter_input";
const TIMEFILTERUNIT = "time_filter_type"
const UNITFILTER = "unit_filter";

const constrcutFilterOptions = (field_id, chartId, timeFilterType, timeFilterUnit, unit)=> {

  var filterObj = {};
  filterObj[FIELDID] = !_.isNil(field_id) ? field_id : null;
  filterObj[CHARTID] = !_.isNil(chartId) ? chartId : null;
  filterObj[TIMEFILTERUNIT] = !_.isNil(timeFilterType) ? timeFilterType : null;
  filterObj[TIMEFILTERVALUE] = !_.isNil(timeFilterUnit) ? timeFilterUnit : null;
  filterObj[UNITFILTER] = !_.isNil(unit) ? unit : null;

  return filterObj;

}
kkbh8khc

kkbh8khc2#

试着写if条件语句,而不是写一个表达式,例如:{ nextCell?.getElementsByTagName(“input”)?.length > 0?nextCell?.getElementsByTagName(“input”)[0].focus():nextCell?.getElementsByTagName(“select”)?.length > 0?nextCell?.getElementsByTagName(“select”)[0].focus():“"; } solution:- function setKeyboardTabEvent(nextCell:()=> void{ return()=>{ if(nextCell?.getElementsByTagName(“input”)?.length > 0){ nextCell?.getElementsByTagName(“input”)[0].focus();} if(nextCell?.getElementsByTagName(“select”)?.length > 0){ nextCell?.getElementsByTagName(“select”)[0].focus();} };

相关问题