Support the ongoing development of Laravel.io →
posted 9 years ago
Views Forms
Last updated 2 years ago.
0

I progress...

in my controller :

public function edit($id)
    {
        //
        $data['banque']=Banque::where('societes_id', $id)
                ->orderBy('nom', 'asc')
                ->get();

        $data['totalbanque'] = Banque::where('societes_id', $id)->count();

        return view('banques.edit',compact('banques'))->with($data,json_encode($data));

    }

I want to access my data in jquery, so i add json_encode($data));

and in my view :

jQuery(function($) {

        $('.table-responsive tbody').on('click', 'tr', function () {
            var id = $('td', this).eq(0).text();


            var dataB = data;

            for (var i = 0, c = dataB.length; i < c; i++) {

                if (dataB.id == id) {
                    alert(dataB.nom);
                }

            //alert(tab);
            //alert( 'You clicked on '+id+'\'s row' );
            }
        } );
    });

But ReferenceError: data is not defined

what is wrong ?

0

I found !

in my controller no change :

public function edit($id)
    {
        //
        $data['banque']=Banque::where('societes_id', $id)
                ->orderBy('nom', 'asc')
                ->get();

        $data['totalbanque'] = Banque::where('societes_id', $id)->count();

        return view('banques.edit',compact('banques'))->with($data);

    }

and in my view :

<script type="text/javascript">

    jQuery(function($){
        $('input').iCheck({
            checkboxClass: 'icheckbox_minimal-blue',
            radioClass: 'iradio_minimal-blue',
            increaseArea: '20%' // optional
        });
    });

    jQuery(function($) {

        $('.table-responsive tbody').on('click', 'tr', function () {
            var id = $('td', this).eq(0).text();


            //var dataB = $data;
            var dataB = {!! json_encode($banque) !!}

            for (var i = 0, c = dataB.length; i < c; i++) {

                if (dataB[i].id == id) {

                    $("input[name=nom]").val(dataB[i].nom);
                    $("input[name=agence]").val(dataB[i].agence);
                    $("input[name=tel]").val(dataB[i].tel);
                    $("input[name=fax]").val(dataB[i].fax);
                    $("input[name=intitule]").val(dataB[i].intitule);
                    $("input[name=adresse1]").val(dataB[i].adresse1);
                    $("input[name=adresse2]").val(dataB[i].adresse2);
                    $("input[name=codepostal]").val(dataB[i].codepostal);
                    $("input[name=ville]").val(dataB[i].ville);
                    $("input[name=codeetablissement]").val(dataB[i].codeetablissement);
                    $("input[name=codeguichet]").val(dataB[i].codeguichet);
                    $("input[name=numerocompte]").val(dataB[i].numerocompte);
                    $("input[name=cle]").val(dataB[i].cle);
                    $("input[name=iban]").val(dataB[i].iban);
                    $("input[name=bic]").val(dataB[i].bic);
                    if (dataB[i].default == 1) {
                        $('input').iCheck('check');
                        //alert(dataB[i].default);
                    }
                    else{
                        $('input').iCheck('uncheck');
                    }
                }
            }
        } );
    });


</script>

It could help some peoples....

0

Sign in to participate in this thread!

Eventy

Your banner here too?

guil182 guil182 Joined 1 Jul 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.