Handlebarsでjsonの多次元配列配列の値が取得できません。
phpで取得した多次元配列の値をjavascriptのHandlebarsを使用して取得したいのですができません。
{{a.0.0}}が問題のコードです。
html
1 <script type="text/javascript" src="bower_components/jquery/dist/jquery.min.js"></script> 2 <script type="text/javascript" src="bower_components/handlebars/handlebars.js"></script> 3 <script type="text/x-handlebars-template" id="tmpl"> 4 <p>a:{{a.0.0}}</p> 5 </script> 6 <script> 7 window.onload = function(){ 8 var source = $('#tmpl').html(); 9 var template = Handlebars.compile(source); 10 var a = [ 11 [ 12 ["A","B","C"], 13 ["D","E","F"], 14 ["G","H","I"] 15 ],[ 16 ["J","K","L","M"], 17 ["N","O","P","Q","R"] 18 ],[ 19 ["S","T","U"], 20 ["V","W"] 21 ] 22 ]; 23 24 25 console.log("a" + a[0][0]); 26 27 var html = template(a); 28 $('#output').html(html); 29 } 30 </script> 31 <title>Document</title> 32</head> 33<body> 34<div id="output"> 35
追記
phpで仮のデータ(後にDBと接続するため)
php
1 public function get($params) { 2 $models = array( 3 array('1111', '1111', '1111', '1111', '1111'), 4 array('2222', '2222', '2222', '22,22', '22,22'), 5 array('3333', '3333', '3333', "3333", "3333"), 6 array('title' => 'タイトル', 7 'name' => '名",前', 8 'hoge' => 'ほげ', 9 'piyo' => 'ぴよ', 10 'fuga' => 'ふが', 11 'fugara' => 'ほげら'), 12 ); 13 return $models; 14 }
phpからバインドしてきたデータ
js
1ReportController.prototype = { 2 /** 3 * イベントバインド 4 */ 5 bind : function () { 6 _http.questionnaire().done(function (response) { 7 console.log(response); 8 }); 9 } 10};
回答1件
あなたの回答
tips
プレビュー