Javascript 在ExtJS中创建路径精灵时出错

Javascript 在ExtJS中创建路径精灵时出错,javascript,extjs4,firebug,Javascript,Extjs4,Firebug,这是我正在使用的代码。这个简单的函数只是为了测试我是否做得正确。显然,我不是。出于我无法理解的原因,除非我注释掉第一个函数,否则我总是会得到相同的错误 // Build an arrow from first to second var buildEdge = function(first, second) { var arrow; arrow = { type: 'path', path: "M " + first.x + " " + first

这是我正在使用的代码。这个简单的函数只是为了测试我是否做得正确。显然,我不是。出于我无法理解的原因,除非我注释掉第一个函数,否则我总是会得到相同的错误

// Build an arrow from first to second
var buildEdge = function(first, second)
{
    var arrow;
    arrow = {
        type: 'path',
        path: "M " + first.x + " " + first.y + " " +
              "L " + second.x + " " + second.y,
        stroke: 'black'
    };
    return arrow;
};

var first = {
    type: 'circle',
    x: 100,
    y: 100,
    radius: 50,

    fill: '#99FF99',
    stroke: '#55CC55',
    'stroke-width': 2
};
// .........
first
second
都是ExtJS精灵。 运行此FireBug时,始终提供以下有用错误:

TypeError:此[(“getPath”+a.type)]不是函数
http://cdn.sencha.io/ext-4.2.0-gpl/ext-all.js
第21行

我已经看过ext-all.js,但我对ExtJS的内部工作原理了解不多,也不想(无论如何,对于这个项目)。我承认我是JavaScript的新手,但我知道这段代码无论如何都会“编译”。是的,当我删除此功能时,其他精灵(
第一个
第二个
)会正确显示


我想我在这里犯了一些愚蠢的新手错误,所以欢迎任何帮助。谢谢

或许可以试试这段代码,看看会发生什么

// Build an arrow from first to second
// surface param is surface instance sprite is to be added to.
var buildEdge = function(first, second, surface)
{
    var arrow;
    arrow = Ext.create('Ext.draw.Sprite', {
        type: 'path',
        path: "M " + first.x + " " + first.y + " " +
              "L " + second.x + " " + second.y,
        stroke: 'black'
    });

    surface.add(arrow);
    arrow.show(true);

  //return arrow if you want to work with it elsewhere outside of method.
};
注意事项:

查看clasificado对surface.add()方法的注释

如果在引发渲染事件后以编程方式添加新精灵,则需要手动调用新精灵的.show(true)方法


也许可以试试这段代码,看看会发生什么

// Build an arrow from first to second
// surface param is surface instance sprite is to be added to.
var buildEdge = function(first, second, surface)
{
    var arrow;
    arrow = Ext.create('Ext.draw.Sprite', {
        type: 'path',
        path: "M " + first.x + " " + first.y + " " +
              "L " + second.x + " " + second.y,
        stroke: 'black'
    });

    surface.add(arrow);
    arrow.show(true);

  //return arrow if you want to work with it elsewhere outside of method.
};
注意事项:

查看clasificado对surface.add()方法的注释

如果在引发渲染事件后以编程方式添加新精灵,则需要手动调用新精灵的.show(true)方法