如何在路由功能之间共享变量?

时间:2016-02-12 13:37:12

标签: javascript node.js express

我正在构建API的服务器端解析器。对我的网站的每个get-request都需要以对api的请求开始,对api的请求总是一样的,所以我想把它放在它自己的函数中。

如何将响应变量从api-function传递给render-function?

<div class="row vertical-offset-100">
      <div class="col-md-4 col-md-offset-4">
<div class="row">
  <div class="span4">
    <%= simple_form_for @load, html: {class: "well", multipart: true } do |f| %>

    <fieldset>
      <h1 class="text-center login-title"><strong> Hey <%= current_user.first_name %></strong> </h1> 
      <h3 class="text-center login-title"><strong> Let's fill the Shipment Details </strong> </h3>
      <%= f.input :pickup, placeholder: "Where Do You Want The Shipper To Arrive?", label: "Pickup Location" %>
      <%= f.input :delivery, placeholder: "Where Do You Want To Move The Shipment?", label: "Delivery Location" %>
      <%= f.input :date, placeholder: "When Do You Want To Ship?", label: "Date Of Shipment" %>
      <%= f.input :truck, :collection => ["Mini(Tempo)", "Tata Ace(Chota Hathi", "Max(MaxiTruck)","Max+(Tata 407"], placeholder: "Choose Your Vehicle", label: "Trucks", :prompt => 'Select Your Vehicle' %>
      <%= f.input :phone, placeholder: "Your Mobile Number", label: "Contact Number" %>
    <div class="text-center">
<%= link_to 'Add release', load_id:  {:remote => true, 'data-toggle' =>  "modal", 'data-target' => '#modal-window'}  %>
  </button>

          </div>
      <% end %>

1 个答案:

答案 0 :(得分:1)

您可以在致电req之前将其分配到next()

req.response = response;

在你的下一个......

var response = req.response;