我正在处理一个页面,其中有两个单选按钮和一个填充了控制器数据的表格。表中显示的数据来自两个不同的类别。 现在我想确保当用户选择不同的单选按钮时,它只显示此按钮的类别而不是两个类别 这是我的尝试
这是检索数据的Controller方法
public function Data(){
$data = App\Equations::get();
return array('aaData'=>$data);
}
以及我如何使用Ajax在视图中接收它
var table = $('#table-active').DataTable({
responsive: {
details: {
type: 'column',
target: -1
}
},
ajax:{"url" : "datatblejson",type:"get",data:{_token: $('meta[name="csrf-token"]').attr('content')}},
buttons: {
dom: {
button: {
className: 'btn btn-default'
}
},
buttons: [
{
extend: 'colvis',
text: '<i class=icon-loop3></i>',
className: 'btn btn-default',
action: function ( e, dt, node, config ) {
$.ajax({
url:'datatblejson', type: 'get', data: {_token: $('meta[name="csrf-token"]').attr('content')}
});
$('#table-active').DataTable().ajax.reload();
}
},
{extend: 'copy',text: '<i title="Copy" class="icon-copy3"></i>'},
{extend: 'csv' ,text: '<i title="Export to CSV sheet." class="icon-file-spreadsheet"></i>'},
{extend: 'excel' ,text: '<i title="Export to excel sheet." class="icon-file-excel"></i>'},
{extend: 'pdf' , text: '<i title="Export to PDF file." class="icon-file-pdf"></i>'},
{extend: 'print', text: '<i title="Print" class="icon-printer"></i>'},
{
extend: 'colvis',
text: '<i class="icon-three-bars"></i> <span class="caret"></span>',
className: 'btn bg-blue btn-icon'
}
]
},
columnDefs: [
{
className: 'control',
orderable: false,
targets: -1
}],
deferRender: true,
columns:[
{"render": function ( type, full, data, meta ) {
return '<a href="#" title="Open profile" class="profile" >'+data.name+'</a>';
}},
{"render": function ( type, full, data, meta ) {
return '<input type="text" name='+data.id+' value='+data.value+'>';
}},
{ "data": null, "defaultContent":'<center><ul class="icons-list"><li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="icon-menu9"></i></a><ul class="dropdown-menu dropdown-menu-right">' +
'<li><a href="#" class="history" ><i class="icon-file-stats"></i> Timeline</a></li>' +
'<li><a href="#" class="profile" ><i class="icon-user"></i> Profile</a></li>' +
'<li><a href="#" class="disconnect"><i class=" icon-file-eye"></i> Disconnect </a></li>' +
'<li><a href="#" class="suspend"><i class=" icon-file-eye"></i> Suspend </a></li>' +
'</ul> </li> </ul></center>'}
//{ "data":null,"defaultContent":"" }
]
});
这里是包含两个单选按钮的表单,我想在选中时更改表格内容
<form action="{{url('update_price')}}" method="get" id="update">
<div class="panel-heading">
<h5 class="panel-title">Update Prices NOW!</h5>
</div>
<div class="row" style="margin-left: 5%">
<h3>Please Choose a Category</h3>
<input class="radio" id="radio-1" name="rd" type="radio" checked value="engineer">
<label tabindex="4" for="radio-1" class="radio-label">Engineer</label>
<br />
<input class="radio" id="radio-2" name="rd" type="radio" value="user">
<label tabindex="5" for="radio-2" class="radio-label">Normal User</label>
<br />
</div>
<div class="panel-body">
</div>
<table class="table" width="100%" id="table-active">
<thead>
<tr>
<th>Name</th>
<th>Cost</th>
</tr>
</thead>
</table>
<button id="button" style="margin-left: 45%;back"></button>
</form>
答案 0 :(得分:1)
您是否尝试使用jquery中的某些功能在单击单选按钮时再次获取数据?并将类别参数添加到ajax请求..
这样的事情:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = ((Activity) getContext()).getLayoutInflater().inflate(R.layout.item_message, parent, false);
}
ImageView photoImageView = (ImageView) convertView.findViewById(R.id.photoImageView);
TextView messageTextView = (TextView) convertView.findViewById(R.id.messageTextView);
TextView authorTextView = (TextView) convertView.findViewById(R.id.nameTextView);
LinearLayout layout = (LinearLayout) convertView.findViewById(R.id.image_container);
FriendlyMessage message = getItem(position);
boolean isPhoto = message.getPhotoUrl() != null;
if (isPhoto) {
messageTextView.setVisibility(View.GONE);
layout.setVisibility(View.VISIBLE);
layout.setMinimumHeight(200);
photoImageView.setVisibility(View.VISIBLE);
Glide.with(photoImageView.getContext())
.load(message.getPhotoUrl())
.into(photoImageView);
} else {
messageTextView.setVisibility(View.VISIBLE);
photoImageView.setVisibility(View.GONE);
layout.setVisibility(View.GONE);
layout.setMinimumHeight(0);
messageTextView.setText(message.getText());
}
//Modified part to displaying messages on right
try {
if (user.getDisplayName().equalsIgnoreCase(message.getName())) {
System.out.println("At Gravity" + user.getDisplayName().toString() + message.getName());
messageTextView.setGravity(Gravity.RIGHT);
authorTextView.setGravity(Gravity.RIGHT);
layout.setGravity(Gravity.RIGHT);
messageTextView.setMaxWidth(200);
authorTextView.setTextColor(Color.CYAN);
}
} catch (NullPointerException e) {
System.out.println("Exception catched");
}
messageTextView.setText(message.getText());
authorTextView.setText("." + message.getName());
return convertView;