0
핸들 막대의 url에서 가져 오는 JSON 데이터를 구문 분석하고 싶습니다. URL에서 JSON 데이터를 얻었습니다. 데이터 객체에 정의했습니다. handlebars.js를 사용하여 데이터를 구문 분석 할 수있는 방법을 알고 싶습니다. handlebars.js를 처음 사용했습니다 각 속성을 정의하지 않고도 얻을 수있는 다른 방법이 있습니까? 내 JSON 데이터가 크기 때문에. 예 : json 데이터가 url에서 가져 오는 것이 handlebars.js에서 구문 분석되지 않습니다.
reportData = {
inquiryId= data.data[0].inquiryId;
}
HTML 코드 :
<script id="address-template" type="text/x-handlebars-template">
{{#with data}}
<p> My id is {{{inquiryId}}}</p>
{{/with}}
</script>
<div class="content-placeholder"></div>
JS 번호 :
var reportData= {};
$(document).ready(function() {
$.ajax({
type:'GET',
url: reportURL,
success : function (data){
var inquiryId= data.data[0].inquiryId;
var theTemplateScript = $("#address-template").html();
console.log(theTemplateScript);
// Compile the template
var theTemplate = Handlebars.compile(theTemplateScript);
// Define our data object
reportData=data;
console.log(reportData);
// Pass our data to the template
var theCompiledHtml = theTemplate(reportData);
// Add the compiled html to the page
$('.content-placeholder').html(theCompiledHtml);
}
})
});
JSON :
{
"success":true,
"errors":{
},
"authenticated":true,
"program":1,
"data":[
{
"id":1,
"date":1505756267000,
"name":"AKKAYA, JORGE",
"productName":"Credit Profile",
"inquiryId":726608
}
]
}
내 출력된다 : 내 이드
이고아무도 도와 줄 수 있습니까? 미리 감사드립니다.