내가 사용 ScalaJS 프로젝트를 만들었습니다Scala.js를 사용하여 javascript 함수를 만드는 방법은 무엇입니까?
http://www.scala-js.org/doc/tutorial.html
http://www.scala-js.org/doc/faq.html에서 문서를 읽기를, 생성하고 자바 스크립트 함수를 호출하는 것은 설명하는 것이하지 않는 것?
JavaScript 함수를 만들고 호출하려면 어떻게해야합니까?
<head>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
</head>
을하지만 어떻게 내가 ScalaJS를 사용하여 아래의 코드를 만들려면 어떻게해야합니까 :
나는 수동으로 index.html을에 머리 요소에 D3를 추가 할 것입니다?
$(document).ready(function() {
var svgContainer = d3.select("body").append("svg")
.attr("width", 1200)
.attr("height", 1200)
.attr("text-align", "center");
testFunction(svgContainer);
});
<script>
function testFunction(svgContainer) {
alert(svgContainer)
}
</script>
전체 index.html을 :
<!DOCTYPE html>
<html>
<head>
<title>Example Scala.js application</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<h1>Example Scala.js application - full-optimized version</h1>
<p>After having compiled and full-optimized properly the code for the application
(using `sbt fullOptJS`), you should see "It works" herebelow.
See README.md for detailed explanations.</p>
<div id="playground">
</div>
<script type="text/javascript" src="./target/scala-2.10/my-project-fastopt.js"></script>
<script type="text/javascript" src="./target/scala-2.10/my-project-launcher.js"></script>
</body>
</html>
업데이트 : fastOptJS
를 사용하여 구축 할 때 callFunction
에서
object ScalaJSExample extends js.JSApp {
def main(): Unit = {
jQuery(dom.document).ready {() => {
val svgContainer = "d3.select(\"body\").append(\"svg\").attr(\"width\", 1200).attr(\"height\", 1200).attr(\"text-align\", \"center\")";
val function = "callFunction(svgContainer)";
}
}
}
def callFunction(svgContainer): Unit = {
}
}
이 svgContainer가 입력해야하는 자바 스크립트 함수로 생성 callFunction
것인가?
jQuery(dom.document).ready {
내에서 svgContainer
및 testFunction
을 만드는 올바른 방법입니까?
업데이트 내용을 참조하십시오. 함수에 svgContainer 매개 변수를 전달하고 동일한 함수를 호출하는 방법을 잘 모르겠습니다. –
@ blue-sky 내 대답을 업데이트했습니다. – sjrd