【问题标题】:Using jessiecode to update jsxgraph objects使用 jessiecode 更新 jsxgraph 对象
【发布时间】:2018-06-19 06:38:46
【问题描述】:

我正在尝试使用 jessiecode 来更新画布对象。看起来我在这里遗漏了一些东西 - fiddleboard.create('circle', [p1, 2.0],{visible:board.jc.snippet("counter < 5 || counter > 10", true, 'counter', false)});board.create('text',[1,1,board.jc.snippet(counter,true,'counter',false)]);

在这个小提琴中,圆圈的可见属性和 1,1 处的文本在单击按钮时不会改变。

【问题讨论】:

    标签: jsxgraph


    【解决方案1】:

    这确实是一个挑战!这里的主要问题是 JessieCode 不允许访问 JavaScript 变量。这是设计使然:出于安全原因,必须阻止对 DOM 的访问。

    这意味着,counter 必须是 JessieCode 变量。可以使用board.jc.parse("code") 执行任意 JessieCode 代码。
    这是完整的示例,请参阅http://jsfiddle.net/a3x5de6t/4/

    var board = JXG.JSXGraph.initBoard('jxgbox', {
        axis: true
    });
    
    // Set JessieCode variable `counter`
    board.jc.parse("counter = 0;");
    
    var p1 = board.create('point', [-2.0, 2.0]);
    
    // Create `function() {return (counter < 5 || counter > 10) ? true: false; }`
    var c1 = board.create('circle', [p1, 2.0],{visible: board.jc.snippet(
            "(counter < 5 || counter > 10) ? true: false", true, '', false)});
    
    // Increase JessieCode variable `counter`
    var button = board.create('button',[1, 4, 'increase counter',
        function() {
            board.jc.parse('counter = counter + 1;');
        }
    ]);
    
    // Create function `function() {return counter; }` 
    var t = board.create('text',[1, 1, board.jc.snippet('counter' , true, '', )]);
    

    最好的祝愿, 阿尔弗雷德

    【讨论】:

    • 谢谢阿尔弗雷德!是否有使用 JessieCode 的指南?我想广泛使用它。据我了解,为了执行 jessiecode,所有变量都应该驻留在 jessiecode 环境中。
    猜你喜欢
    • 2018-06-01
    • 1970-01-01
    • 2012-05-14
    • 2020-12-10
    • 2016-09-13
    • 2019-06-28
    • 2012-01-31
    • 2023-03-22
    • 1970-01-01
    相关资源
    最近更新 更多