title: Uncaught TypeError: Cannot set properties of undefined (setting 'where')
body: <p>Would like to ask solution on uncaught TypeError where my html run &quot;a&quot; and &quot;b&quot;/&quot;c&quot; for the first time the page is load, then on my search condition, it will run &quot;d&quot; &quot;e&quot;, when in search condition display unit not equal to &quot;CASES&quot;, it runs fine where it will go var option and display the table. But when it met the condition &quot;CASES&quot;, it shows <em>Uncaught TypeError: Cannot set properties of undefined (setting 'where')  LINE &quot;options1.where = data.field;&quot;</em></p>
  <pre class="lang-js prettyprint-override"><code>layui.use(['form', 'element', 'laydate', 'jquery', 'layer', 'table'], function () {
      var $ = layui.jquery,
          layer = layui.layer,
          form = layui.form,
          table = layui.table,
          searchDate = '';
          var laydate = layui.laydate;
          laydate.render({
              elem: '#reportDate', 
              lang: 'en',
              done: function (value) {
                  console.log(value); 
                  searchDate = value;
              }
          });   
  var displayUnit = $('[name=displayUnit]').val();
  console.log(&quot;a&quot; + displayUnit);
  if (displayUnit == &quot;CASES&quot;) {
    console.log(&quot;b&quot; + displayUnit);
    var options1 = {
      elem: '#resultMonitoringTable',
      id: 'resultMonitoring',
      limit: Number.MAX_VALUE,
      page: false,
      loading: true,
      method: 'GET',
      url: '../../collection/resultMonitoringData',
      response: {
        statusName: 'code',
        dataName: 'data',
        statusCode: 200,
        msgName: 'message',
        countName: 'totalCount'
      },
      cols: [
        [{
            title: 'Select',
            width: '10%',
            align: 'center',
            toolbar: '#orderListBar'
          },
          {
            field: 'delinquency',
            title: 'Delinquency',
            width: '15%',
            align: 'center',
            templet: function(s) {
              var delinquency = s.delinquency;
              if (delinquency === '6') {
                result = 'M7';
                return result;
              } else if (delinquency === '0') {
                result = 'M1';
                return result;
              } else if (delinquency === '1') {
                result = 'M2';
                return result;
              } else if (delinquency === '2') {
                result = 'M3';
                return result;
              } else if (delinquency === '3') {
                result = 'M4';
                return result;
              } else if (delinquency === '4') {
                result = 'M5';
                return result;
              } else if (delinquency === '5') {
                result = 'M6';
                return result;
              } else {
                result = '&gt;=M8';
                return result;
              }
  
            }
          },
          {
            field: 'cases',
            title: 'Cases',
            width: '20%',
            align: 'center',
            templet: function(s) {
  
              result = s.cases;
              return result;
            }
          },
          {
            field: 'billing',
            hide: true,
            templet: function(s) {
  
              result = formatMoney(s.billing);
              return result;
            }
          },
          {
            field: 'collection',
            title: 'Collected',
            width: '20%',
            align: 'center',
            templet: function(s) {
              result = formatMoney(s.collection);
              return result;
            }
          },
          {
            field: 'billing' &amp;&amp; 'collection',
            title: 'Balance',
            width: '20%',
            align: 'center',
            templet: function(s) {
              result = formatMoney(s.billing - s.collection);
              return result;
            }
          },
          {
            field: 'billing' &amp;&amp; 'balance',
            title: 'Pct%',
            width: '15%',
            align: 'center',
            templet: function(s) {
              result = formatMoney((s.collection / s.billing) * 100) + '%';
              return result;
            }
          },
  
        ]
      ],
      done: function(res) {
        data = res.data;
        console.log(&quot;result: &quot; + data);
      }
    };
    table.render(options1);
  } else {
    console.log(&quot;c&quot; + displayUnit);
    var options = {
      elem: '#resultMonitoringTable',
      id: 'resultMonitoring',
      limit: Number.MAX_VALUE,
      page: false,
      loading: true,
      method: 'GET',
      url: '../../collection/resultMonitoringData',
      response: {
        statusName: 'code',
        dataName: 'data',
        statusCode: 200,
        msgName: 'message',
        countName: 'totalCount'
      },
      cols: [
        [{
            title: 'Select',
            width: '10%',
            align: 'center',
            toolbar: '#orderListBar'
          },
          {
            field: 'delinquency',
            title: 'Delinquency',
            width: '15%',
            align: 'center',
            templet: function(s) {
              var delinquency = s.delinquency;
              if (delinquency === '6') {
                result = 'M7';
                return result;
              } else if (delinquency === '0') {
                result = 'M1';
                return result;
              } else if (delinquency === '1') {
                result = 'M2';
                return result;
              } else if (delinquency === '2') {
                result = 'M3';
                return result;
              } else if (delinquency === '3') {
                result = 'M4';
                return result;
              } else if (delinquency === '4') {
                result = 'M5';
                return result;
              } else if (delinquency === '5') {
                result = 'M6';
                return result;
              } else {
                result = '&gt;=M8';
                return result;
              }
  
            }
          },
  
          {
            field: 'billing',
            title: 'Billing',
            width: '20%',
            align: 'center',
            templet: function(s) {
  
              result = formatMoney(s.billing);
              return result;
            }
          },
  
          {
            field: 'collection',
            title: 'Collected',
            width: '20%',
            align: 'center',
            templet: function(s) {
              result = formatMoney(s.collection);
              return result;
            }
          },
          {
            field: 'billing' &amp;&amp; 'collection',
            title: 'Balance',
            width: '20%',
            align: 'center',
            templet: function(s) {
              result = formatMoney(s.billing - s.collection);
              return result;
            }
          },
          {
            field: 'billing' &amp;&amp; 'balance',
            title: 'Pct%',
            width: '15%',
            align: 'center',
            templet: function(s) {
              result = formatMoney((s.collection / s.billing) * 100) + '%';
              return result;
            }
          },
  
        ]
      ],
      done: function(res) {
        data = res.data;
        console.log(&quot;result: &quot; + data);
      }
    };
  
    table.render(options);
  }
  
  form.on('submit(search)', function(data) {
  
    if (searchDate.length === 0) {
      layer.msg('Report Date can\'t be empty!', {
        icon: 2
      });
    }
    var displayUnit = $('[name=displayUnit]').val();
    if (displayUnit == &quot;CASES&quot;) {
      console.log(data);
      options1.where = data.field;
      console.log(&quot;d&quot; + displayUnit);
      table.reload('resultMonitoring', options1);
    } else {
      console.log(&quot;e&quot; + displayUnit);
      console.log(data);
      options.where = data.field;
      table.reload('resultMonitoring', options);
    }
     table.on('tool(resultMonitoringTable)', function (obj) {
                  var data = obj.data; 
                  var layEvent = obj.event; 
                   var reportDate = $('[name=reportDate]').val();
                   var displayUnit = $('[name=displayUnit]').val();
                   console.log(&quot;report date and display unit&quot; +reportDate+displayUnit);
                  if (layEvent == &quot;view&quot;) {
                      console.log(&quot;view: &quot; + data.delinquency + reportDate);
                      location.href = '/collection/view?delinquency='+ data.delinquency+'&amp;reportDate='+data.reportDate+'&amp;displayUnit='+data.displayUnit;
                      
                  }
              });
  
     function formatMoney(amount, decimalCount = 2, decimal = &quot;.&quot;, thousands = &quot;,&quot;) {
          try {
              decimalCount = Math.abs(decimalCount);
              decimalCount = isNaN(decimalCount) ? 2 : decimalCount;
  
              const negativeSign = amount &lt; 0 ? &quot;-&quot; : &quot;&quot;;
  
              let i = parseInt(amount = Math.abs(Number(amount) || 0).toFixed(decimalCount)).toString();
              let j = (i.length &gt; 3) ? i.length % 3 : 0;
  
              return negativeSign + (j ? i.substr(0, j) + thousands : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, &quot;$1&quot; + thousands) + (decimalCount ? decimal + Math.abs(amount - i).toFixed(decimalCount).slice(2) : &quot;&quot;);
          } catch (e) {
              console.log(e)
          }
      };
  });
  </code></pre>