如何在Zeppelin中的javascript中将变量放入z ZeppelinContext? [英] How to put a variable into z ZeppelinContext in javascript in Zeppelin?
问题描述
在Scala和Python中,它是:
In Scala and Python it's:
z.put("varname", variable)
但是在javascript中,我得到了(在控制台中)
But in javascript I get (in the console)
Uncaught ReferenceError: z is not defined
我真正想做的是使用Zeppelin中的z.angular("varname")
从Scala代码访问一个javascript变量,但是我没有运气:(
What I really want to do is access a javascript variable from Scala code using z.angular("varname")
in Zeppelin, but I'm having no luck :(
在一个单元格中完全需要
In full need in one cell something like
%angular
<script>
var myVar = "hello world";
// some magic code here!
</script>
然后在另一个单元格中
println(z.angular("myVar"))
更新:
到目前为止,这是我所拥有的,因为我更像是后端/数据科学类的人,所以我完全在暗中st刺.提前为我的绝望表示歉意.
This is what I have so far, I'm completely stabbing in the dark, since I'm more of a back end / data science kind of guy. So apologies in advance for my front end hopelessness.
单元格1:
z.angularBind("myVar", "myVar")
z.angularBind("msg", "msg")
请注意,我不知道在第二个参数中输入什么内容.
Note I have no idea what to put in the second argument.
单元格2:
%angular
<div ng-app>
<div id="outer" ng-controller="MsgCtrl">
You are {{msg}}
</div>
<div onclick="change()">click me</div>
</div>
<script>
var myVar = "hello world";
function MsgCtrl($scope)
{
$scope.msg = "foo";
// also experimented with $scope.msg = myVar;
}
function change() {
var scope = angular.element($("#outer")).scope();
scope.$apply(function(){
scope.msg = 'Superhero';
})
}
</script>
单元格3:
z.angular("msg")
z.angular("myVar")
无论我做什么,我都会得到null
或var名称.
And no matter what I do I just either get null
or the var name.
我也看不到任何按钮或要单击的任何内容.
I don't see a button either or anything to "click".
推荐答案
在Angular解释器中.我们可以
-
在html内容中使用
Use within html content
{{name}}
绑定
ng-model='name'
与ng-click或其他角度指令一起使用或设置.
Use or set with ng-click or other angular directives.
ng-click="name='Rockie'"
根据许多SO的说法,在angular的控制器外部修改范围变量不是一个好习惯.我也没有让它在齐柏林飞船上工作.虽然有一个普通js小提琴示例.
并在Spark解释器中.我们可以
-
绑定
Bind with
z.angularBind("name", "Knock Data")
取消绑定
z.angularUnbind("name")
使用来获取值,首先需要绑定变量,否则它将为null.
Get the value with, the variable need be bind first, otherwise it will get null.
z.angular("name")
使用
z.angularWatch("name", (oldValue: Object, newValue: Object) => {
println(s"value changed from $oldValue to $newValue"
})
z.angularWatch("name", (oldValue: Object, newValue: Object) => {
println(s"value changed from $oldValue to $newValue"
})
在角度绑定旁边. 动态表单是为最终用户提供互动的好方法
Beside the angular bind. The Dynamic Form is a good way to give interactive for end users
-
输入
Input
z.input("number", 1).toString.toInt
选择没有默认值
z.select("Day", Seq(("1", "Mon"), ("2", "Tue")))
选择默认值
z.select("Day", "1", Seq(("1", "Mon"), ("2", "Tue")))
检查
z.checkbox("good applications", Seq(("1", "Zeppelin"), ("2", "Highcharts"), ("3", "Spark")))
这篇关于如何在Zeppelin中的javascript中将变量放入z ZeppelinContext?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!