如何在ajax中显示laravel刀片代码

时间:2014-12-31 07:24:52

标签: php jquery ajax laravel blade

在我的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(会话::得到(&#39;权限&#39;)[$模块))                                                     {{Render :: tableButtons(Session :: get(&#39; permissions&#39;)[$ module],$ actions [&#39; table&#39;],array(&#34; [ID]&# 34; =&gt; $ promotion-&gt; id),array())}}                                             @万一                                             

1 个答案:

答案 0 :(得分:0)

您可以在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>
相关问题