이 코드를 사용하여 서버에서 메서드를 호출하고 있습니다.
Meteor.call 'getTitle', post.url, (error, title) ->
console.log 'client side title is: ' + title
그리고 서버에서 :
Meteor.methods
getTitle: (url) ->
fullURL = addhttp(url)
read fullURL, (err, article, meta) ->
if err
console.log err
err
else
console.log article.title
article.title
그리고 클라이언트에서 반환 값은 정의되지 않습니다. 읽기 함수에서 article.title 값을 반환하고 싶습니다. 읽기 함수가 호출되면 계속 진행되고 반환 데이터가있는 콜백을 기다리지 않기 때문입니다. 읽기 함수 아래에 반환 값을 포함하도록 함수를 수정하면 이것을 명확하게보기 위해 반환 값이 올바르게 전송됩니다.
Meteor.methods
getTitle: (url) ->
fullURL = addhttp(url)
read fullURL, (err, article, meta) ->
if err
console.log err
err
else
console.log article.title
article.title
return 'this return value is sent!'
하지만 어떻게이 메서드를 호출하고 읽기 함수 (article.title)에서 콜백에있는 값을 반환하도록 할 수 있습니까?
선물을 사용하십시오.
@Future = Npm.require('fibers/future')
그때:
Meteor.methods
getTitle: (url) ->
...
fut = new Future()
doSomething ->
...
fut.return {success: true}
fut.wait()
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다