简体   繁体   English

“ jcanvas”我无法在图层本身中获取“数据属性”

[英]“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: 一个简单实用的解决方案是预先指定您的数据对象,以便在drawRect()调用范围内可以访问它:

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? 可以使用GetLayer()吗? 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. 但是,如果您从jCanvas外部进行跟踪,就我所了解的jCanvas的目的而言,您不必担心jCanvas的外部数据。而是动态获取并调整Layers属性。

I'm having the same kind of problems with my project too. 我的项目也遇到同样的问题。

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

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