laravel auto完整文本视图

时间:2016-11-03 14:34:24

标签: javascript laravel-5

我使用的是Laravel 5.2。

这是我的代码

export = "files/extract.xlsx"
future_days = 12
writer = pd.ExcelWriter('files/new_report-%s.xlsx' % (date.today()), engine ='xlsxwriter')
workbook = writer.book
df = pd.read_excel(export)
df.to_excel(writer, 'Full Log', index=False)
log_sheet = writer.sheets['Full Log']

new_headers = ('todays date', 'Milestone Date')
log_sheet.write_row('CW1', new_headers)

# This for loop just writes in the formula for my new columns on every line
        for row_num in range(2, len(df.index)+2):
            log_sheet.write_formula('CX' + str(row_num),'=IF(AND($BS{0}>1/1/1990,$BT{0}<>"Yes"),IF($BS{0}<=$CW{0},$BS{0},"Date In Future"),IF(AND($BW{0}>1/1/1990,$BX{0}<>"Yes"),IF($BW{0}<=CW{0},$BW{0},"Date In Future"),IF(AND($CA{0}>1/1/1990,$CCW{0}<>"Yes"),IF($CA{0}<=CW{0},$CA{0},"Date In Future"),IF(AND($CE{0}>1/1/1990,$CF{0}<>"Yes"),IF($CE{0}<CW{0},$CE{0},"Date In Future"),IF(AND($CI{0}>1/1/1990,$CJ{0}<>"Yes"),IF($CI{0}<CW{0},$CI{0},"Date In Future"),IF(AND($CM{0}>1/1/1990,$CN{0}<>"Yes"),IF($CM{0}<CW{0},$CM{0},"Date In Future"),"No Date"))))))'.format(row_num))
            log_sheet.write_formula('CW' + str(row_num), '=TODAY()+' + str(future_days))
            log_sheet.write_formula('CY' + str(row_num), '=IF(AND(AI{0}>DATEVALUE("1/1/1900"), AH{0}>DATEVALUE("1/1/1900"),A{0}<>"Test",A{0}<>"Dummy Test"),NETWORKDAYS(AH{0},AI{0}-1),"Test")'.format(row_num))

现在问题是我手动浏览链接{{URL :: route('auto')}},其中显示为json view

所以问题是它没有给出,因为它应该在这里看到 main view

但是如果我将代码“{{URL :: route('auto')}}”改为source:[“a”,“b”]。它正确输出。那么问题出在哪里呢?

1 个答案:

答案 0 :(得分:1)

所以这是解决方案。

对于javascript,请写如下

$(function()
      {
           $( "#q" ).autocomplete({
            source: "{{URL('auto')}}",
            minLength: 1,
            select: function(event, ui) {
            $( "#q" ).val(ui.item.value);
            }       
             });
       });

对于控制器,请添加如下

namespace App\Http\Controllers;

    use Illuminate\Http\Request;
    use App\Http\Controllers\Controller;
    use Illuminate\Support\Facades\Input;
    use App\Product;
    use DB;

    class SearchController extends Controller
    {

    public function autoComplete()
        {

            $term = Input::get('term');

            $results = array();

            $queries = DB::table('skills')
            ->where('skill', 'LIKE', '%'.$term.'%')
            ->take(9)->get();

        foreach ($queries as $query)
        {
            $results[] = [ 'id' => $query->ID, 'value' => $query->skill];
        }


        return response()->json($results);
        }

    }

问题出在控制器中,它获取了get变量的空值,查询构建器返回了数据库中的所有结果。我已经添加了一个库并关联变量如下并解决了问题。

use Illuminate\Support\Facades\Input;
$term = Input::get('term');

希望它能帮助其他人解决同样的问题。

我希望以下链接会有所帮助。

  1. https://gist.github.com/imranismail/10200241?signup=true

  2. https://gist.github.com/manoj-nandakumar/11beb90916dfbdc6af7a