2013-05-01 1 views
3

여기에 jsfiddle 코드 handsontable에 대한 링크입니다. 버튼을 누르면 데이터 세트가 콘솔로 이동합니다. 내 웹 페이지에는 두 가지 JavaScript 코드 조각이 있습니다. 그 중 하나는 입니다. 어떻게하면 (콘솔 대신) 다른 스크립트에 속하는 배열로 데이터를 전송 (덤프) 할 수 있습니까?static 배열을 Java와 같이 모든 스크립트에 표시 할 수있는 방법이 있습니까?handsontable 데이터를 동일한 페이지의 다른 JavaScript로 전송하는 방법은 무엇입니까?

<div id="mytable" class="handsontable"> </div> 
<script> 
// Here the user inserts the data to the handsontable. As she presses the button, data should go to the second piece of script. 
</script> 

... 

<div id="target" class=""> </div> 
<script> 
//the target array is here, and it needs to be filled with the data from the above piece of script as the button is pressed. 
</script> 
+0

두 개의 스크립트를 결합 해 보았습니까? –

+0

@Pizdy 네, 그걸 시도했습니다. 불행하게도 두 개의 조각이 두 개의 서로 다른 JQuery이기 때문에이 작업을 수행 할 수 없습니다. 그들은 두 개의 다른 클래스입니다. – Buras

+0

jsfiddle을 어떻게 열 수 있습니까? – CHEBURASHKA

답변

2

예를 들어 그것을 할 수있는 많은 방법이 있습니다 :

1) 데이터

<div id="mytable" class="handsontable"> </div> 

<script> 
// set data 
    window.data = getCarData(); 

    $("#example1").handsontable({ 
    data: window.data 
    }); 
</script> 

<div id="target" class="class"> </div> 

<script> 
    //get data 
    var array = window.data; 
</script> 

2.

)를 사용하는 경우를 저장할 전역 변수를 만들고 여기에 는 계획이다 jQuery :

// you can bind data to element 
$('table').data('key', 'value'); 

// and then get it 
$('table').data('key');