アイテムの配列を受け取る js 関数があります。関数自体は、jquery html 関数の呼び出しを使用して動的に html コンテンツを作成します。問題は、追加された html 内に配列を正しく埋め込む方法を覚えていないことです。例えば、
var ErrorsNotifier = {
init: function(items) {
var template = '<div id="message">';
template += '<div id="id">some message.<br /><br />';
template += '<div class="errorsList">error desc</div></div>';
template += '<a href="#" class="goback" onclick="ErrorsNotifier.Back("+items+");"></a>';
template += '<a href="#" class="proceed" onclick="ErrorsNotifier.Next();"></a>';
template += '<input type="image" src="someimage" alt="" class="" onclick="window.open("someurl");"/></div>';
$("#content").html(template);
}
}
HTML が本文にレンダリングされた後、アンカー タグをクリックすると、次のエラーが返されます -Uncaught SyntaxError: Unexpected identifier
ブラウザでアンカータグを調べると、次のように表示されます
a href="#" class="goback" onclick="ErrorsNotifier.Back([object Object]);"