2012-09-10 1 views
0

tideSDK 애플리케이션에서 JavaScript의 루비 변수에 액세스 할 수 없습니다. 현재 사용중인 SDK 버전은 현재 최신 버전 인 1.2.0.RC4입니다. 다음은 기본 예제입니다.TideSDK | JavaScript에서 루비 변수에 액세스하기

<!DOCTYPE html> 
<html> 
<head> 
    <title>Hello World</title> 
    <style type="text/css"> 
    body {background: #fff;} 
    </style> 
</head> 
<body> 
    <h1>Hello World</h1> 

    <script type="text/python"> 
     helloP = "Hello from Python!"; 
    </script> 

    <script type="text/ruby"> 
     $helloR = "Hello from Ruby!"; 
    </script> 

    <script type="text/php"> 
     $helloPHP = "Hello from PHP!"; 
    </script> 

    <script type="text/javascript"> 
     alert("Hello from JavaScript!"); 
     alert(helloP); 
     alert(helloPHP); 
     alert(helloR); 
    </script> 
</body> 
</html> 

이 예에서는 Python, PHP 및 Ruby 변수에 값을 선언하고 할당했습니다. JavaScript alert() 함수는 python 및 PHP 변수에서 작동하지만 ruby ​​변수에서는 작동하지 않습니다. 그래서 alert (helloP); 및 경고 (helloPHP); 해당 변수의 내용으로 작업하고 팝업 대화 상자를 표시하지만 alert (helloR)와 함께 표시되는 것은 없습니다.

반면에 루비 기능은 자바 스크립트에서 볼 수 있습니다. 그래서 ruby_function이 루비 함수라면 자바 스크립트 경고 (ruby_function())가 작동합니다.

JavaScript는 어떻게 루비 변수를 볼 수 있습니까? 어떤 제안?

+0

Win7x64 SDK 1.2.0RC6d에서 확인 -이를 확인할 수 있습니다. helloP 및 HelloPHP 변수가 모두 window 객체의 속성이되었지만 helloR 변수는 그렇지 않습니다. 나에게 어떤 kroll 버그가 보인다. –

답변

2

1.2 릴리스에서는 작동하지 않습니다.

인라인이 아닌 포함 파일에 루비가 있어야합니다.

그런 다음 예상대로 작동합니다. 자원 폴더에서

: 리소스 폴더에

<html> 
    <head> 
     <script> 
     Titanium.include("ruby.rb"); 
     </script> 
    </head> 
<body style="background-color:#ccc;margin:0"> 
</body> 
</html> 
<script> 
    console.log(window.crim); 
    console.log(crim); 
    alert(crim.foo); 
</script> 

index.html을 : ruby.rb

window.crim = { 
    'foo' => 'bar' 
} 

https://wiki.appcelerator.org/display/guides/Using+Titanium+Desktop+with+Ruby를 참조하십시오 - 제목 티타늄 데스크탑 1.2.0에서 정보를 찾습니다. RC1 SDK 및 최신.

+0

Meeeche의 솔루션은 Windows 7에서 작동하지 않습니다. – sp2012