doumu8911 2019-08-14 07:14
浏览 522

未捕获的DOMException:无法在'Element'上执行'setAttribute':'1'不是Laravel刀片模板中的有效属性名称

I have a problem in my code, it is functional and but it bugs me with the console error I am getting from chrome.

My blade template code is:

<select name="business_unit_id" class="form-control">
 @foreach (App\Models\BusinessUnit::all() as $data)
  <option value="{{ $data->id }}"
   {{ old('business_unit_id', $cost_centers->business_unit_id ?? null)
    != $data->id ?: 'selected' }}>
    {{ $data->code.' - '.$data->descr }}
  </option>
 @endforeach
</select>

The console error are:

app.js:41637 Uncaught DOMException: Failed to execute 'setAttribute' on 'Element': '1' is not a valid attribute name.
    at baseSetAttr (http://ksakuws1137/js/app.js:43932:8)
    at setAttr (http://ksakuws1137/js/app.js:43907:5)
    at Array.updateAttrs (http://ksakuws1137/js/app.js:43862:7)
    at invokeCreateHooks (http://ksakuws1137/js/app.js:43218:22)
    at createElm (http://ksakuws1137/js/app.js:43105:11)
    at createChildren (http://ksakuws1137/js/app.js:43202:9)
    at createElm (http://ksakuws1137/js/app.js:43103:9)
    at createChildren (http://ksakuws1137/js/app.js:43202:9)
    at createElm (http://ksakuws1137/js/app.js:43103:9)
    at createChildren (http://ksakuws1137/js/app.js:43202:9)

The culprit is below, but that is needed to in order for the program to behave correctly.

{{ old('business_unit_id', $cost_centers->business_unit_id ?? null)
    != $data->id ?: 'selected' }}>

Anyone encounter the same issue and have a resolution? Thanks.

  • 写回答

1条回答 默认 最新

  • dsbfbz75185 2019-08-15 10:59
    关注

    I found the solution by changing the code in blade template from:

    {{ old('business_unit_id', $cost_centers->business_unit_id ?? null)
        != $data->id ?: 'selected' }}>
    

    To:

    {{ old('business_unit_id', $cost_centers->business_unit_id ?? null)
                                    != $data->id ? '' : 'selected' }}
    

    The culprit then is the "?:", maybe not compliant with HTML5?

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog