dtxob80644
2019-06-25 20:11
浏览 154
已采纳

如何在laravel blade.php文件中调用检查所选选项的函数?

I create a fuction for checking selected option and I want to call it in the for the selected part.

@foreach ($stocks as $stock)
   <option value="{{ $stock->id }}" ..... > {{ $stock->name }}</option>
@endforeach

for the .... should be the place to call the function that I created but I don't know how to call it. I tried :

@foreach ($stocks as $stock)
   <option value="{{ $stock->id }}" {{ CheckCombo($stock->id, $product- 
         product_type }} > {{ $stock->name }}</option>
@endforeach

for the function CheckCombo, it returns 'selected' back.

图片转代码服务由CSDN问答提供 功能建议

我创建了一个用于检查所选选项的函数,我想在 中为所选部分调用它。< / p>

  @foreach($ stock as $ stock)
&lt; option value =“{{$ stock-&gt; id}}”.....&gt;  {{$ stock-&gt; name}}&lt; / option&gt; 
 @ endforeach 
   
 
 

....应该是调用函数的地方 我创建但我不知道怎么称呼它。 我试过:

  @foreach($ stocks as $ stock)
&lt; option value =“{{$ stock-&gt; id}}”{{CheckCombo(  $ stock-&gt; id,$ product- 
 product_type}}&gt; {{$ stock-&gt; name}}&lt; / option&gt; 
 @ endforeach 
   
 
  

对于函数CheckCombo,它返回'selected'返回。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doupai6875 2019-06-25 20:26
    已采纳

    When you loop the option values check it with the db value and if it gets a match echo seleceted

     @foreach ($stocks as $stock)
       <option value="{{ $stock->id }}"  @if( ($stock->id) == ($product-> 
             product_type)) selected @endif > {{ $stock->name }}</option>
    @endforeach
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题