Mustache를 사용하여 폴더의 앨범 이름을 인쇄하는 간단한 서버 (localhost : 8080)를 만들었지 만 작동하지 않습니다. server.js 구문 분석의 브라우저 결과 8080/페이지/홈 :
콧수염이 nodejs 서버에서 객체를 렌더링하지 않습니다.
방법 내 설정 기능은
1. 내가 터미널
2. 로컬 호스트 (nodejs로 작성)를 server.js를 실행하는 것입니다 basic.html에 home.js
내 home.js에서
3. basic.html 호출을 호출 요청은 다음과 같습니다
$(function()
{
var tmpl, // main template - html
tdata= {}; // json data object feeding the template
// Initialise page
function show()
{
// Load html template
$.get("/templates/home.html", function(d)
{
tmpl= d;
});
//Retrieve server data, then initialize the page
$.getJSON("/albums.json", function(d)
{
$.extend(tdata, d.data);
});
// After completion of AJAX calls, parse the template
// replacing mustache tags with vars
$(document).ajaxStop(function()
{
var finald= mine(tdata);
var rendp= Mustache.render(tmpl, finald);
$("body").text(rendp);
});
}
show();
});
function mine(data)
{
if(data.albums && data.albums.length> 0)
data.have_albums= true;
else
data.have_albums= false;
return data;
}
위 (home.js 그래서 입력 누른 후 Mustache.render (.., ..) home.js의 일부
에서 문제가 분명히있다
<div id="alblis">
{{#have_albums}}
<p> Number of albums: {{albums.length}}
</p>
{{/have_albums}}
<ul id="albums">
{{#albums}}
<li class="album">
<a href=
"http://localhost:8080/albums/{{album_name}}"> {{album_name}}
</a>
</li>
{{/albums}}
{{^albums}}
<li> Sorry, no albums </li>
{{/albums}}
</ul>
</div>
:) 인 home.html을에서 호출 브라우저에서 http://localhost:8080/pages/home
에서 server.js가 실행에, 나는 터미널 실행 server.js
incoming req.: (GET) /pages/home
incoming req.: (GET) /content/jquery.js
incoming req.: (GET) /content/mustache.js
incoming req.: (GET) /content/home.js
incoming req.: (GET) /templates/home.html
incoming req.: (GET) /albums.json
사이드 노트에 다음을 얻을 : 터미널에 curl localhost:8080/albums.json
실행의 결과는
01 23,516,{"error":null,"data":{"albums":[{"album_name":"friends","title":"friends"},{"album_name":"travel","title":"travel"}]}}
: http://localhost:8080/pages/home
하지만 그 일이되지 않습니다!