如何在 AJAX 中显示 Laravel 刀片代码


how to show laravel blade code in ajax

in my index.balde.php

{{ Form::open(['url'=>'/crm/promotion/multi_destroy', 'method'=>'POST', 'id'=>'form_delete_all','class'=>'form-horizontal']) }}
                                @foreach ($promotions as $promotion)
                                <tr class="odd gradeX data-table-item">
                                        <td><input type="checkbox" class="multidel" name="multidel_{{$promotion->id}}"></td>
                                        <td>{{$promotion->name}}</td>
                                        <td>{{$promotion->i_name}}</td>
                                        <td>{{ substr($promotion->descr, 0, 100)}}...</td>
                                        <td>{{$promotion->start}}</td>
                                        <td>{{$promotion->end}}</td>
                                        <td>
                                        @if(isset(Session::get('permissions')[$module]))
                                                {{ Render::tableButtons(Session::get('permissions')[$module], $actions['table'] ,array("[ID]" => $promotion->id), array() ) }}
                                        @endif
                                        </td>
                                    </tr>
                                @endforeach
                            {{Form::close()}}

当一个动作发生变化时,我将通过以下方式显示

if($('#ed').val()!="" && $('#sd').val()=="")
    {
        $.ajax({
            type: "GET",
            dataType: "json",
            url: '/crm/promotion/promotion_search_end',
            data:'end='+$('#ed').val(),
            beforeSend: function(){
            },
            success: function (data) 
            {                  
                //$('.data-table-item').html('');
                $('.data-table-item').empty();

                console.log(data);
                $.each(data, function(index, item_data)
                {
                    //console.log(item_data.id);
                    $('#data-table').footable();
                    $('#data-table').append('<tr class="odd gradeX data-table-item"><td><input type="checkbox" class="multidel" name="multidel_'+item_data.id+'"></td><td>'+item_data.name+'</td><td>'+item_data.i_name+'</td><td>'+item_data.descr+'</td><td>'+item_data.start+'</td><td>'+item_data.end+'</td><td></td></tr>');     
                }); 
            },
            complete: function(){
                // do the following after success is done.
            },
            error: function(){
                // do the following if there is error. 
            }
        });
    }

我想在 ajax 中使用。如何使用?

@if(isset(Session::get('permissions')[$module])) {{ render::tableButtons(Session::get('permissions')[$module], $actions['table'] ,array("[ID]" => $promotion->id), array() ) }} @endif

你可以在javascript中使用laravel刀片代码。在您的情况下,您可以像下面这样使用

<script>
    @if(isset(Session::get('permissions')[$module])) 
        var value = {{ Render::tableButtons(Session::get('permissions')[$module], $actions['table'] ,array("[ID]" => $promotion->id), array() ) }} 
        alert(value);
    @endif
</script>