你好,我有这个代码
$(function() {
bonsai.run(document.getElementById('movie'), {
code: function() {
var rect= new Rect(0, 0, 100, 100);
rect.on('multi:pointerdown', function(e) {
$("#dialog-form").dialog("open");
});
},
width: 500,
height: 400,
});
});
Run Code Online (Sandbox Code Playgroud)
当我点击我的矩形时,我有这个错误:
ReferenceError:$未定义
我怎样才能获得关于jquery的参考?
BonsaiJS创建一个新的执行上下文(通常是一个Web工作者),您传入的代码bonsai.run在不同的范围内执行,其中jQuery不可用.有关BonsaiJS如何执行代码的详细信息,请访问此处.
但要解决您的问题,您可以与所谓的BonsaiJS跑步者上下文进行通信:
$(function() {
var movie = bonsai.run(document.getElementById('movie'), {
// note: this function will be stringified and sent to the runner context
code: function() {
var rect= new Rect(0, 0, 100, 100).fill('red').addTo(stage);
rect.on('multi:pointerdown', function(e) {
// this is how you would pass data with your message
stage.sendMessage('openDialog', {
id: '#dialog-form'
});
// no data:
// stage.sendMessage('openDialog', {});
});
},
width: 500,
height: 400,
});
movie.on('load', function() {
movie.on('message:openDialog', function(data) {
$(data.id).dialog("open");
});
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
454 次 |
| 最近记录: |