【问题标题】:"jcanvas" I can't get "data property" within the layer itself“jcanvas”我无法在图层本身中获取“数据属性”
【发布时间】:2014-09-21 06:23:32
【问题描述】:
// 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);

我可以从图层中取出数据。


// second case

$('canvas').drawRect({

  layer: true,

  data: { w: 300 },

  fillStyle: '#585',

  x: 100, y: 100,

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

});

我无法获取图层本身的数据。

【问题讨论】:

    标签: javascript object layer jcanvas


    【解决方案1】:

    一个简单实用的解决方案是预先指定您的数据对象,以便在您的drawRect() 调用范围内可以访问它:

    var rectData = { w: 300 };
    
    $('canvas').drawRect({
    
      layer: true,
    
      data: rectData,
    
      fillStyle: '#585',
    
      x: 100, y: 100,
    
      width: rectData.w, height: 50
    
    });
    

    【讨论】:

      【解决方案2】:

      你以前可以使用 GetLayer() 吗?把它赋值给一个变量,然后放回去?

      但是,如果您从 jCanvas 外部跟踪它,据我了解 jCanvas 的用途,您不应该担心 jCanvas 的外部数据。而是即时抓取图层属性并进行调整。

      我的项目也遇到了同样的问题。

      【讨论】:

        猜你喜欢
        • 2013-12-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-12-03
        • 2015-03-04
        • 1970-01-01
        • 1970-01-01
        • 2017-06-17
        相关资源
        最近更新 更多