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 ?
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....
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community