我试图通过js.dart与Dart使用paper.js。NoSuchMethodError与dart.js
有很多似乎工作,但我也需要从paper.js的方法importSVG
。当我尝试访问js.context.paper.project.importSVG(query("#svg"));
时,我得到NoSuchMethodError
。这在某种程度上是因为该方法被注入到项目中 - 请参阅下面的paper.js中的代码。
如何从Dart访问importSVG
方法?
/* paper.js */
new function() {
function importSVG(node, clearDefs) {
// ...
}
Item.inject(/** @lends Item# */{
/**
* Converts the passed node node into a Paper.js item and adds it to the
* children of this item.
*
* @param {SVGSVGElement} node the SVG DOM node to convert
* @return {Item} the converted Paper.js item
*/
importSVG: function(node) {
return this.addChild(importSVG(node, true));
}
});
Project.inject(/** @lends Project# */{
/**
* Converts the passed node node into a Paper.js item and adds it to the
* active layer of this project.
*
* @param {SVGSVGElement} node the SVG DOM node to convert
* @return {Item} the converted Paper.js item
*/
importSVG: function(node) {
this.activate();
return importSVG(node, true);
}
});
};
快速浏览一下http://paper.js,似乎你的调用'js.context.paper.project.importSVG(query(“#svg”));'是正确的。你能粘贴整个错误吗? –
感谢您的回答。 “打破异常:NoSuchMethodError:找不到方法:'importSVG'”从js.dart抛出:1038 –
很奇怪。您可以使用_chrome开发人员工具_测试您是否在JavaScript中定义了此方法?在控制台中输入'paper.project.importSVG'。你应该看到类似'function(node){this.activate(); return importSVG(node,true); }' –