2012-04-23 3 views
1

내 웹 사이트에 대한 내 의견 시스템에서 작업하고 있는데 전체 필드 값을 가져올 수 없습니다. 나는이 스크립트 https://github.com/podio/jquery-mentions-inputJquery 언급 입력 : 출력 데이터 문제

return { 
    init : function (options) { 
    settings = options; 

    initTextarea(); 
    initAutocomplete(); 
    initMentionsOverlay(); 
    }, 

    val : function (callback) { 
    if (!_.isFunction(callback)) { 
     return; 
    } 

    var value = mentionsCollection.length ? elmInputBox.data('messageText') : getInputBoxValue(); 
    callback.call(this, value); 
    } 
} 

을 사용하고

함수 발는 값을 돌려 하나입니다!

이것은 값을 가져 오기 위해 사용하는 코드입니다.

$('#commentInput').mentionsInput('val', function(comment){ var test = comment; }); 
    alert(test); 

나는이 다음 내 데이터베이스로 전송 될 수 있도록이 함수에서 값 주석/테스트를 추출하는 방법을 찾고 싶습니다 (작동하지 않습니다).

다음 코드를 사용하면 경고 상자에 좋은 정보가 표시됩니다.

('#commentInput').mentionsInput('val', function(comment) { alert(comment); }); 

내가 시도하고 그것이 작동되도록하는 몇 가지 다른 조작을 시도했지만 난 항상 같은 오류를 얻고 있었다 [개체 개체] 또는 [HTMLDivElement와]

내가이 바보 쉽게 뭔가 확신, 그러나 나는 그것을 이해할 수 없다.

희망 누군가가

('#commentInput').mentionsInput('val', function(comment) { alert(comment); });

올바른 정립이다, 나를

좋은 일

요리스

답변

0

요리스을 가지고 도움을 줄 수.

sendToDatabase가 데이터베이스에 (아약스와 서버 스크립트를 통해) 인수 및 업로드 그것과 같은 의견을 받아들이는 기능이
('#commentInput').mentionsInput('val', function(comment) { 
    sendToDatabase(comment); 
}); 

.... 뭔가를 다음과 같이 당신은, 한 단계 더 갈 필요 like :

function sendToDatabase(comment){ 
    $ajax({ 
     url: 'path/to/server/script', 
     type: "GET", //or "POST" 
     data: { "comment": comment }, 
     success: function(){ 
      //here display something to confirm that the upload was successful 
     }, 
     error: function(){ 
      //here display something to indicate that the upload was not successful 
     }, 
    }); 
} 
+0

감사합니다. 그러나 나는 왜 당신이 값을 추출하여 변수에 넣을 수 없는지 궁금해하고 있습니까? @ Beetroot-Beetroot 다시 한번 감사 드리며 좋은 하루 되세요! –

+0

'.mentionsInput()'의 두 번째 매개 변수로 정의 된 함수는 형식 변수'comment'를 가진 콜백 함수입니다. 'comment'의 범위는 콜백 함수로 한정됩니다. 'comment'에 접근하려했던 곳은 범위를 벗어 났지만 아직 설정되지 않았습니다. –