2017-10-10 12 views
1

私はstorelocater.jsをGoogleマップの複数の場所に使用しており、画像のある場所に応じて情報を表示しています。私は1つの画像だけを表示できますが、私は情報パネルの中に複数の画像を表示したいと思います。リンクここでは、このjavascriptでオブジェクトの配列をプリントし、htmlタグで印刷する

Image how I want to show

は私のコードは

var panelDiv = document.getElementById('panel'); 
storeLocator.Panel.NO_STORES_IN_VIEW_HTML_ = '<li class="no-stores">The nearest outlet:</li>'; 
    var Store = storeLocator.Store; 
    Store.prototype.generateFieldsHTML_ = function(fields) { 
    var html = ''; 
    html += '<div class="store-data">'; 
    if(this.props_['title']){ 
     html += '<div class="title"><div class="img-list clearfix">' + 
     for (var i = 0; i <= this.props_[images].length; i++) { 
     console.log(this.props_[images[i]]); 
     // <img src=' + this.props_['images'] + '> 
     } 
    + '</div></div>' 
    } 
    html += '</div>'; 
    return html; 
    } 
    var data = new storeLocator.StaticDataFeed; 
    data.setStores([ 
    new storeLocator.Store('store02', new google.maps.LatLng(27.67663,85.31093), null, {images: ["img/thapathalil.jpg","img/thapathalil.jpg","img/thapathalil.jpg"]}) 
    ]); 

あり、それは示しています キャッチされないでSyntaxError:...

のための予期しないトークンどのように私はこの問題を解決することができますが?どのように私は、「画像」私はタイプミスがあると思い事前

+0

あなたが直面している問題/エラーを追加してください。またはそれはどのようにレンダリングされるかもしれませんか? –

+0

自分のコードを編集しました。チェックアウトしてください。 –

+0

@NiranjanShakyaあなたは[** my answer **](https://stackoverflow.com/a/46663141/3669624)を下記にチェックしましたか? –

答えて

0

は実際にあなたがUncaught SyntaxError: Unexpected token for...を得ました文字列連結ステートメントのは、+符号の直後にあります。

変更このコード:

html += '<div class="title"><div class="img-list clearfix">'; 
for (var i = 0; i <= this.props_['images'].length; i++) { 
    console.log(this.props_['images'][i]); 
    html += '<img src=' + this.props_['images'][i] + '>'; 
} 
html += '</div></div>' 

注:

html += '<div class="title"><div class="img-list clearfix">' + 
for (var i = 0; i <= this.props_[images].length; i++) { 
    console.log(this.props_[images[i]]); 
    // <img src=' + this.props_['images'] + '> 
} 
+ '</div></div>' 

は、次のように

  • あなたはhtml 変数に文字列の連結を分離しなければなりませんfor l複数の行に+との連結を使用するのではなく、html +=を使用してください。
  • this.props_[images]で、それはthis.props_['images']あるべき場所とthis.props_[images[i]]で、それはthis.props_['images'][i]あるべき場所のように、あなたのオブジェクトにアクセスしている間に2 ''間のプロパティ名をラップすることを確認します。
  • html変数のデカルトと連結の最初の2行は、var html = ''; html += '<div class="store-data">';に短縮され、ちょうどvar html = '<div class="store-data">';に短縮されます。
+0

ありがとうございます。完了しました。 –

0

THANKSの内側に位置を取得することができます。この変更:

console.log(this.props_[images[i]]) 

console.log(this.props_['images'][i]) 

へのそして、あなたは

を使用する必要がありますので、これを試してください:あなたはを使用しているため

for (var i = 0; i < this.props_['images'].length; i++) { 
    console.log(this.props_['images'][i]); 
} 
+0

まだ表示されています Uncaught SyntaxError:予期しないトークン... –

+0

興味深い部分は完全なエラーメッセージです。これをあなたの質問に追加してください。 – RWAM

+0

同じ問題... –

関連する問題