Rails:用搜索框中的结果数据填充表
Rails: Fill Table with resulting data from a search box
正如问题所说,我正试图用rails 4中搜索框的结果填充表中的数据。我在谷歌上搜索了一下,但我找不到答案,甚至找不到如何做到这一点的例子。
这是我的观点:
<% title @sale.client_name %>
<div class="hero-unit">
<CENTER><H1><%= @sale.client_name %> </H1>
<br>
<p>
Numero de Factura:<br>
<%= @sale.check_number %>
</p>
<p>
Nit del Cliente:<br>
<%= @sale.nit%>
</p>
<p>
Fecha de venta:<br>
<%= @sale.created_at %>
</p>
<p>
Total Venta:<br>
<%= @sale.price %>
</p>
<p>
<h2><Center><%= link_to_function "Ver Detalle de Venta", "$('#hide').toggle()" %> </Center></h2>
<div id="hide" style="display:none">
<table class="table table-striped">
<thead>
<tr>
<th><Center>Nombre</Center></th>
<th><Center>Codigo del SubProducto</Center></th>
<th><Center>Marca</Center></th>
<th><Center>Categoria</Center></th>
<th><Center>Precio</Center></th>
</tr>
</thead>
<tbody>
<% @sale.subproducts.each do |subproduct| %>
<tr>
<td><CENTER><%= subproduct.product.name %></CENTER></td>
<td><CENTER><%= subproduct.code %></CENTER></td>
<td><CENTER><%= subproduct.product.brand %></CENTER></td>
<td><CENTER><%= subproduct.product.category %></CENTER></td>
<td><CENTER><%= subproduct.product.sale_price %></CENTER></td>
<td><%= link_to 'Eliminar de venta', :controller => :subproducts, action => 'eliminar_subproducto_venta', :id => subproduct.id, :sale_id => @sale.id %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
</p>
<% if @sale.confirmed == false %>
<p>
<h2><Center><%= link_to_function "Agregar Producto a venta", "$('#subproduct').toggle()" %></Center></h2>
<div id="subproduct" style="display:none">
<table class="table table-striped">
<thead>
<tr>
<th><Center>Nombre</Center></th>
<th><Center>Codigo del SubProducto</Center></th>
<th><Center>Marca</Center></th>
<th><Center>Categoria</Center></th>
<th><Center>Precio De Venta</Center></th>
</tr>
</thead>
<tbody>
<% @subproducts.each do |subproduct| %>
<tr>
<%if subproduct.available == true || subproduct.available == "NULL"%>
<td><CENTER><%= subproduct.product.name %></CENTER></td>
<td><CENTER><%= subproduct.code %></CENTER></td>
<td><CENTER><%= subproduct.product.brand %></CENTER></td>
<td><CENTER><%= subproduct.product.category %></CENTER></td>
<td><CENTER><%= subproduct.product.sale_price %></CENTER></td>
<td><%= link_to 'Agregar a Venta', :controller => :subproducts, :action => 'agregar_subproducto_venta', :id => subproduct.id, :sale_id => @sale.id %></td>
<% end %>
</tr>
<% end %>
</tbody>
</table>
</div>
</p>
<%if @sale.price !=0 %>
<%= link_to 'Confirmar Venta', :controller => :sales, :action => 'confirm_sale', :identificator => @sale.id%><br>
<%end%>
<%= link_to 'Cancelar Venta', :controller => :sales, :action => 'cancel_sale', :deletor => @sale.id%><br>
<%end%><br>
<%= button_to 'Volver', sales_path, :method => :get, :class => 'btn btn-default' %><br>
</CENTER>
</div>
我希望当用户点击带有特定参数的搜索按钮时,可以刷新第二个表。
有人能帮我吗??我已经尝试了将近两周了,但没有结果=(
有很多方法可以做到这一点。最简单的方法是为您的表创建js视图searach_table.js.erb
,它将返回您渲染的html表
你的js视图:
$("#your_second_table_container").html(<%= escape_javascript(render(partial: 'search_results', locals: {subproducts: @subproducts}))%>)
以及您的搜索链接:
<%= link_to 'Search', <ypur_rout_to_js_view_action>, remote: true %>
相关文章:
- 如何在chrome扩展中存储数据/结果,以及如何使用setTimeout使其只被调用一次
- 无法使用streams/highland.js从mongodb的结果中获取数据
- 从 Angular 数据工厂中的 HTTP POST 请求接收未定义的结果
- 停止 jQuery 自动完成以过滤/搜索结果并填充整个源数组数据
- 有没有一个简单的解决方案可以根据3个数据找到结果
- 将base64图像数据作为src分配给图像时,Firefox和Chrome上的结果不一致
- jqueryajax帖子将我发送到操作页面,并且不会显示结果数据
- OrientDB:在服务器端函数中访问查询结果数据
- 如何在从 ajax 获取时拆分结果数据
- 对 asmx Web 服务的 Ajax/json 调用成功完成,但无法显示结果数据
- 从 AJAX JSON 结果数据填充选择列表
- 如何将查询结果数据传递到Express.js和Mysql中的视图
- Json序列化器vs .net序列化类的JQuery AJAX结果数据
- 如何使用ajax在select2中显示多个结果数据
- 我如何通过电子邮件发送包含mysql结果数据的html表在php中的一个按钮
- 等待Callback和我们的结果数据从这个函数中取出另一个进程
- 如何在Angular promise请求中获取结果数据
- Rails:用搜索框中的结果数据填充表
- 没有使用流星http包获取结果数据
- 将对象压入数组,然后通过结果数据结构进行循环