2016-05-29 2 views
0

ビュー内で{{#each rows}}ループを使用していますが、反復処理中のオブジェクト配列は描画されません。 res.send(rows)を使用するとオブジェクト配列が表示され、結果が返されます。 このサーバーをcloud9プラットフォームで実行すると、オブジェクト属性でいっぱいになった表がレンダリングされますが、Amazon Web Serverでこのサーバーを実行しようとすると、ビューがレンダリングされますが、#eachループはレンダリングされず、ページソースを見ると、行は受信されていないようです。しかし、再びres.send(rows)を実行すると、行オブジェクト配列が表示されます。 私は本当に助けていただければ幸いです。ハンドルバーjsはオブジェクト配列を描画しません。mysql query(nodejsサーバ内)

<h1>Donors</h1> 
    <div class="col-md-8"> 
    <table class="table table-striped table-hover"> 

    <thead> 

     <tr> 

      <th>Name 

      <th>Address 

      <th>City 

      <th>State 

      <th>Zip 

      <th>Specific Location</th> 

     </tr> 

    </thead> 

    <tbody> 

     {{#each rows}} 

      <tr> 

       <td>{{this.name}} 

       <td>{{this.street_address}} 

       <td>{{this.city}} 

       <td>{{this.state}} 

       <td>{{this.zip}} 

       <td>{{this.specific_location}} 

      </tr> 

     {{/each}} 

    </tbody> 

</table> 
</div> 
<div class="col-md-4"> 
<form role="form" action="/Donors/business" method="POST"> 

    <fieldset> 

     <legend>See Available Food From a Specific Donor:</legend> 

      <div class="form-group"> 

       <label for="Specific_donor">Pick a Specific Donor:</label> 

       <select class="form-control" name="business_id" id="business_id"> 

        <option>--Select Donor--</option> 

         {{#each businesses}} 

           <option value={{this.id}}>{{this.name}}</option> 

         {{/each}} 

       </select> 

      <input type="submit" id="entrySubmitABusiness" class="btn btn-primary"> 

    </fieldset> 

</form> 
</div> 

答えて

1

試してみてください:

var express = require('express'); 
var mysql = require('./dbContentPool.js'); 
var bodyParser = require('body-parser'); 
var app = express(); 
var handlebars = require('express-handlebars').create({defaultLayout:'main'}); 
app.use(express.static('public')); 
app.engine('handlebars', handlebars.engine); 
app.set('view engine', 'handlebars'); 
app.set('port', 3000); 
app.use(express.static(__dirname + '/public')); 
app.use(bodyParser.urlencoded({ extended: false })); 
app.use(bodyParser.json()); 
app.get('/Donors/business', function(req, res, next){ 
      mysql.pool.query('SELECT * FROM ' + 'business', function(err, rows, fields){ 

      if(err){ 

        next(err); 

        return; 

      } 

      res.render('Donors/business/index', rows); 

    }); 
}); 

//ここで 'ドナー/ビジネス/インデックス' と呼ばれる私の見解ではコードです。ここで

//は私のサーバーのコードがあります

res.render('Donors/business/index', {rows: rows}); 
+0

これは修正されました。ありがとうございます! 私の質問を投稿する前に、私は試みました:res.render( 'Donors/business/index'、{行}); ですが、予期しないトークン、というエラーが表示されました。もう一度、ありがとう! – wilsonsk

関連する問題