简体   繁体   中英

“jcanvas” I can't get “data property” within the layer itself

// 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.

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

});

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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