0
// first case

$('canvas').drawRect({

  layer: true,

  data: { w: 300 },

  fillStyle: '#585',

  x: 100, y: 100,

  width: 100, height: 50

});

alert($('canvas').getLayer(0).data.w);

I can get the data out of the layer.


// second case

$('canvas').drawRect({

  layer: true,

  data: { w: 300 },

  fillStyle: '#585',

  x: 100, y: 100,

  width: $('canvas').getLayer(0).data.w, height: 50

});

I can't get the data within the layer itself.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
IvanK
  • 65
  • 1
  • 6

2 Answers2

0

An easy and practical solution would be to specify your data object beforehand so that it is accessible within the scope of your drawRect() call:

var rectData = { w: 300 };

$('canvas').drawRect({

  layer: true,

  data: rectData,

  fillStyle: '#585',

  x: 100, y: 100,

  width: rectData.w, height: 50

});
caleb531
  • 4,111
  • 6
  • 31
  • 41
0

Can you use GetLayer() before? assign it to a variable, then put it back?

But if your tracking it from outside jCanvas, as I understand the purposes of jCanvas, you're not supposed to be worrying about external data for jCanvas.. instead grabbing the Layers properties on the fly and adjusting.

I'm having the same kind of problems with my project too.