2017-09-03 3 views
0

를 가져 그리고 사용자의 사진호출 노드 기능은 내가 기사 목록을 표시 EJS 템플릿을 사용하고

템플릿

<%for (var i=0; i< articles.length; i++){%> 
    <div class="ui-block list-article"> 
     <article class="hentry post video"> 
      <div class="post__author author vcard inline-items"> 
       <div id="userProfilImage" class="userProfilImage"> 
        <img src="<%= articles[i].user.image %>" alt="author" /> 
       </div> 
      </div> 
     </article> 
    </div> 
<% } %> 

Nodejs를 유혹 할 때 PARAM으로 현재 기사 노드 함수를 호출하고 싶습니다 파일과 같은 사용자 이미지를 유혹 할 때 app.locals.getUserPopupInfo 함수를 호출하는 방법

app.locals.getUserPopupInfo = function(article){ 
    article.user.name= "blablabla"; 
} 

:

<div id="userProfilImage" class="userProfilImage" onmouseenter="getUserPopupInfo(articles[i])"> 
    <img src="<%= articles[i].user.image %>" alt="author" /> 
</div> 

감사

편집 :

내가 이걸 발견 :

<div id="userProfilImage" class="userProfilImage" onmouseenter="<%= getUserPopupInfo(articles[i]) %>"> 
    <img src="<%= articles[i].user.image %>" alt="author" /> 
</div> 

그러나 그것은 페이지로드에 getUserPopupInfo 함수를 호출합니다. 이것을 방지하는 방법? 나는 그것을 마우스에서만 입력하고 싶다.

+0

페이지로드시 Ejs 주입이 호출됩니다. 그 모든 생각. – Itamar

답변

1

데이터를 가져 오기 위해 REST 호출 GET을 생성하는 방법이있다. 클라이언트에서 서버 기능을 호출하면 안됩니다.

nodejs rest tutorial 또는 express.js를 참조

편집 : 당신이 here을 볼 수 있듯이, 당신은 이벤트 처리에 클라이언트 측 JS를 사용할 필요가

.

따라서 서버 호출을 사용하여 해당 데이터를 검색해야합니다.

+0

이 답변에서 가능한 https://stackoverflow.com/a/13294515/6002163을 보았습니다. 이런 모습을 보여 주실 수 있습니까? –

+0

<%%> – Itamar

+0

으로 함수 호출을 둘러보십시오. 내 대답을 업데이트했습니다. 살펴볼 수 있습니까? –