【发布时间】:2021-08-14 16:30:02
【问题描述】:
public function store( $customername)
{
$projectname=DB::table("selectproject")->where("customername",$customername)->pluck("projectname","id");
$paidamount = DB::table("payment")->where("projectname",$projectname)->sum("amount","id");
$sitenumber = DB::table("sites")->where("projectname",$projectname)->pluck("sitenumber","id");
$array = array( $projectname, $paidamount, $sitenumber);
return json_encode($array);
}
my blade file
@include('projects.home')
<form action="{{ route('siteallocate.store') }}" method="post" >
@csrf
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Select customer :</strong>
<select class="form-control" name="customername">
<option selected="true" disabled="disabled" >--Select--</option>
@foreach ($data as $row)
<option class="form-control" value="{{$row->customername }}" >{{ $row->customername }}
</option>
@endforeach
</select>
</div>
</div>
<div id="tableview" >
</div>
</form>
<script>
jQuery(document).ready(function (){
jQuery('select[name="customername"]').on('change',function(){
var alreadyAdded = [];
var categoryID = jQuery(this).val();
if(categoryID)
{
jQuery.ajax({
url : '/hi/'+categoryID,
type : "GET",
dataType : "json",
success:function(data)
{
$('#tableview').html("")
jQuery.each(data, function(key,value){
//if(data === null) { alert('empty') } // skip nulls
if ($.inArray(this.value, alreadyAdded) !== -1) { return; }
$('#tableview').html("")
$('#tableview').append('<table class="table table-bordered" >
<tr >
class="bg-info"> <th> Customername </th> <th> Projectname </th> <th> Amount </th> <th> Sitenumber
</th> </tr>
<tr>??
<td> ' + categoryID+'</td> <td> ' +data[0][0]+'</td> <td> ' + data[0][1]+'</td> <td> <div
class="col-xs-12 col-sm-12 col-md-12"> <select class="form-control" > <option> ' +
data[0][3]+'</option> </select> </div> </td>
</tr> </table>');
alreadyAdded.push(this.value);
});
}
});
}
});
});
</script>
通过从下拉列表中选择客户名称来显示表格,数据来自数据库
customername in function store () 我必须将 customername 和 projectname 列放在表中
站点编号应该放在我尝试使用 data[0][0]['3'] 之类的索引号的选择框中
但是有没有办法确定下一个键??它在表中显示[Object object]。
这个问题怎么出?
【问题讨论】:
-
请阅读如何提问:stackoverflow.com/help/how-to-ask 并举一个简单的例子。
-
帮帮我兄弟我会尽力而为
-
你需要自己做一些研究。如果没有您确切想要的任何示例,我们将无法为您提供帮助。你目前得到的结果是什么?你到底卡在哪里了?
-
@Swati {"name":{"3":"gopal"},"amt":[{"amount":74500}],"site"{"18":"gopal1" ,"19":"gopal2"}}
-
只有一行,并且站点编号将在下拉列表中显示多个