样式jQuery自动完成以添加图像和额外的字段/变量

时间:2016-01-14 19:51:00

标签: html css jquery-ui laravel-5.1 jquery-ui-autocomplete

enter image description here

我想设置字段及其jQuery自动完成的下拉列表,但是我只想通过控制器,因为在那里,我能够连接我需要的变量并将其发送到Blade上的jQuery自动完成文件。但是连接只是将变量作为一个字段回应出来,我希望像输出到这篇文章的图像那样设置输出的样式。我如何实现这一目标?

这是控制器:

public function SelectLocationPlaces(Request $userAdressRequest)
    {
        $term = $userAdressRequest->term;
        $data = LocationPlaces::where('name', 'LIKE', '%'.$term.'%')->take(10)->get();
        $countries = Country::all();
        $countryFlag = CountryFlag::all();
        $results = array();

        foreach ($data as $key => $value) {

            foreach ($countries as $key => $values) {
                if($value->country_id === $values->iso_alpha2){
                    $countrySelected = $values->name;
                    $selectedCapital = $values->capital;
                }
            }

            foreach ($countryFlag as $key => $valueFlag) {
               if($countrySelected === $valueFlag->name){
                    $countryPerFlag = $valueFlag->flag;
                    $countryCurrency = $valueFlag->currency;
                }
                }

                $results[] = 
                **

['value'=>$value->name .$value->timezone_id .$countrySelected, ];

**
        }
        return Response::json($results);
    }

这是Blade文件:

<DIV align="center"><SPAN class="div-header">USER ADDRESS</SPAN></DIV>

                <div>{!! Form::text('city_town', Input::old('city_town'), ['class'=>'css-classes', 'placeholder'=>'area/city', 'id'=>'city_town']) !!}</div>
                <div>{!! Form::text('state_province_region', Input::old('state_province_region'), ['class'=>'css-classes', 'placeholder'=>'state/province', 'id'=>'state_province_region']) !!}</div>

                <script type="text/javascript">
                    $('#city_town').autocomplete({
                        source: '{{ url('json/redirects') }}',
                        minLength: 1,
                        autofocus: true,
                        select: function(e, ui){
                            $('#state_province_region').val(ui.item.state_province_region);
                            $('#name').val(ui.item.name);
                        }
                    });
                </script>

0 个答案:

没有答案