我想将数据从我的编排传递到webjs,传递的值将通过javascipt将其显示在html中。我可以成功通过它,但问题是它只会显示1-3秒。我这样做正确吗?
这是我来自choregraphe(python)的代码:
def onLoad(self):
#put initialization code here
pass
def onUnload(self):
self.memory = None
#put clean-up code here
pass
def onInput_onStart(self):
data = ['apple','mango','juice']
self.memory.raiseEvent("myData", data)
def onInput_onStop(self):
self.onUnload()
box is stopped
self.onStopped()
这是我的javaschipt从Pepper获取数据的代码:
var session = new QiSession();
$(document).ready(function(){
getData();
});
function getData(){
session.service('ALMemory').then(function(ALMemory){
ALMemory.subscriber("myData").then(function(subscriber) {
subscriber.signal.connect(function(data){
"display to html here"
});
});
});
}
答案 0 :(得分:1)
您的Choregraphe代码中充满了错误,并且您可以删除无用的样板内容,这应该足够了:
def onLoad(self):
self.memory = self.session().service("ALMemory")
def onInput_onStart(self):
data = ['apple','mango','juice']
self.memory.raiseEvent("myData", data)
...至于javascript方面,有两件事要做:
结合在一起,将像这样:
var session = new QiSession();
function updateDisplay(data) {
"display to html here"
}
session.service('ALMemory').then(function(ALMemory){
ALMemory.getData("myData").then(updateDisplay);
ALMemory.subscriber("myData").then(function(subscriber) {
subscriber.signal.connect(updateDisplay);
});
});
答案 1 :(得分:0)
尝试使用ALMemory.getData,而不是ALMemory.subscriber。 这可能对您有用:
var session = new QiSession();
$(document).ready(function(){
getData();
});
function getData(){
session.service('ALMemory').then(function(ALMemory){
ALMemory.getData("myData").then(function(data) {
"display to html here"
});
});
}