0
나는 분명히 그것은 string
을 반환 javascript를 사용하여 html 템플릿에서 렌더링 된 문자열을 반환하는 방법은 무엇입니까?
function format(d) {
// `d` is the original data object for the row
return '<div class="expandedRow" style="padding: 10px; border-style: solid; border-width: 0px 1px; border-color: #f0f0f0;">' +
'<table cellpadding="5" cellspacing="0" border="0" style="width: 100%;">' +
'<tr>' +
'<td>Full name:</td>' +
'<td>' + d.name + '</td>' +
'</tr>' +
'<tr>' +
'<td>Extension number:</td>' +
'<td>' + d.extn + '</td>' +
'</tr>' +
'<tr>' +
'<td>Extra info:</td>' +
'<td>And any further details here (images etc)...</td>' +
'</tr>' +
'</table>'+
'<div>';
}
아래 같은 자바 스크립트 함수가 있습니다. 그러나 html 템플릿이 복잡해지면 return 문에 모든 것을 넣기가 어렵습니다.
일부 html 파일에서 템플릿을 가지고 (template.html
) 템플릿을 렌더링하고 매개 변수 'd
'에 대한 템플릿을 렌더링하고 결과 문자열을 반환 할 수 있습니까?
내가
return renderTemplate('template.html', d);
변수를 연결하고 그 변수를 반환하면 ... – Rayon
ES6 템플릿 문자열을 사용하면 쓰기가 더 쉬울 수 있습니다. – gcampbell
[MustacheJS] (https://github.com/janl/mustache.js)와 같은 템플릿 라이브러리를 찾으십시오. –