简体   繁体   English

如何在JSXGraph中传递元素对象而不是id?

[英]How to pass element object instead of id in JSXGraph?

I'm trying to change 我正在尝试改变

var brd2 = JXG.JSXGraph.initBoard('box', {boundingbox: [-8.75, 2.5, 8.75, -2.5]});

as

var brd2 = JXG.JSXGraph.initBoard(this.$('#box'), {boundingbox: [-8.75, 2.5, 8.75, -2.5]});

Since dynamic elements are created inside backbone views, I need to initialize JSXGraph for each element with the id "box". 由于动态元素是在主干视图内创建的,因此我需要为每个ID为“ box”的元素初始化JSXGraph。

With the following hack it is possible to pass the object instead of the id to JSXGraph. 通过以下技巧,可以将对象而不是ID传递给JSXGraph。 First you need an invisible div with eg the id "dummy". 首先,您需要一个不可见的div,例如ID为“ dummy”。 Then the board is initialised with this dummy id and we have to make corrections afterwards. 然后,使用该虚拟ID初始化板,然后我们必须进行更正。 Let's further assume that 让我们进一步假设

var board = JXG.JSXGraph.initBoard('dummy', {axis:false,
    boundingbox: [-10,30,10,-10], keepaspectratio:false});

var obj = document.getElementById('box'); // or this.$('#box')

board.removeEventHandlers();
board.container = 'box';
board.containerObj = obj;
//
// Supply the dimensions of the box
board.renderer = new JXG.SVGRenderer(obj, {width: 800, height: 800});
board.setBoundingBox([-10,30,10,-10], false);
board.addEventHandlers();

Please note, that specifying axis:true or grid:true in initBoard() will not work. 请注意,在initBoard()中指定axis:truegrid:true无效。

Hope that helps, Alfred 希望能有所帮助,阿尔弗雷德

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM