入力フォームでオートコンプリートを使用して候補を出すことはできているのですが、
候補の表示方法が、下記のように名前の先頭に・が付いてしまいます。
・nike
・newbaranse
・mizuno
候補の表示方法をセレクトボックスにしたいのですが、どうしたらよいのでしょうか?
よろしくお願いします。
blade
php
1 <label for="brand_name" class="col-sm-2 control-label">ブランド名 </label> 2 <input id="brand_name" name="key" class="input-sm form-control" placeholder="2文字以上入力" value=""> 3 . 4 . 5 . 6<script> 7$( function() { 8 $( "#brand_name" ).autocomplete({ 9 source: 'brand_sample', 10 minLength: 2, 11 select: function(event, ui) { 12 $('#brand_name').val(ui.item.value); 13 } 14 }); 15 } ); 16</script>
Controller
php
1public function sample(){ 2 3 $term = Input::get('term'); 4 $names = array() 5 $brands = DB::table('b_name') 6 ->where('name','like','%'.$term.'%') 7 ->take(20) 8 ->get(); 9 10 foreach($brands as $brand){ 11 $names[] = ['label' => $brand->brand,'value' => $brand->brand]; 12 } 13 14 return Response::json($names); 15 }
回答1件
あなたの回答
tips
プレビュー