在此 ROR 应用程序中,如果用户更改任何输入值,我将尝试显示/重新显示结果计算。使用 Chrome 上的开发人员工具,我可以确定已使用下面的 Javascript 计算并返回了适当的结果。我可以选择任何输入值的更改并重做计算。但是我无法让 Javascript 显示结果。
下面我添加了 Javascript、视图的相关部分(一个主要 - 一个部分)以及控制器的相关部分。
javascript - Drill.js.coffee 我有理由确定我遗漏了一些东西,这些东西使我能够将适当的代码放在我用 ??? 指示的位置
$('document').ready ->
if $('#evaluation_assumption_params').length == 1
drill_id = $('.form.assumption').attr('data-drillid')
$('#evaluation_assumption_params').change((event) ->
event.preventDefault()
loadAssumptionChange drill_id
)
loadAssumptionChange = (drill_id)->
data = $('#evaluation_assumption_params').serialize()
console.log data
$.ajax
url:"/drills/#{drill_id}/projection.json"
type:"post"
dataType: 'json'
data: data
success: (data,success,xhr)->
# ??? - tried numerous statements including
# $('#place_to_add_projection_results').html(data)
# $('#ajax').html("<%= escape_javascript(render(:partial => 'drills/evaluation_results')).html_safe %>")
# What should go here ???
部分 - _assessment_results.html.erb
<%= simple_form_for :result_list, :html => { class: 'infogroup', id: "evaluation_results", :method => :post },
remote: true do |f| %>
<%= content_tag :header, "Results", class: 'infogroup-header'%>
<%= content_tag :div, class: 'infogroup-body' do %>
<%= content_tag :table, class: 'info', border: 0, cellspacing: 5, cellpadding: 0 do %>
<tr>
<th>Company</th>
<th>SP</th>
<th>Mkt Cap</th>
...
</tr>
<% if @result_list.present? %>
<% @result_list.each do |result| %>
<tr>
<td><%= result.listing_name %></td>
<td><%= number_to_currency(result.listing.share_price_dollars,
:precision => 3, :delimiter => ',') %></td>
…
与控制器动作对应的主屏幕 -investor.html.erb 此屏幕调用的上述部分以及 javascript
<% content_for :title, "Drill Investor - Valuations" %>
… more heading stuff
<section>
<div class="form assumption" data-drillid="<%= @drill.id %>">
<%= render 'assumption_params' %>
</div>
<div class="form">
<div id="place_to_add_projection_results">
<%= render 'evaluation_results' %>
</div>
</div>
控制器
class DrillsController < ApplicationController
before_filter :current_user
...
def investor
# screens associated allow entry of data as well as display of the results
end
def projection
result_list = Evaluation.generate_projection(@drill.drill_interests, assumption_params)
render json: result_list
end
非常感谢任何帮助
皮埃尔