Dojo无法通过ID获取元素

时间:2014-12-17 08:35:33

标签: javascript html dojo

我试图使用Dojo设置按钮事件监听器。一旦按钮点击,它将执行地理编码功能。以下是代码:

require (["esri/map", "esri/dijit/Scalebar", "esri/layers/FeatureLayer", "esri/dijit/Legend","dojo/_base/array","dojo/parser","dijit/layout/BorderContainer","dijit/layout/ContentPane","dijit/layout/AccordionContainer","esri/InfoTemplate","dojo/dom-construct",
    "esri/tasks/locator","esri/graphic","esri/symbols/SimpleMarkerSymbol","esri/symbols/Font","esri/symbols/TextSymbol","esri/Color","dojo/number","dojo/dom","dijit/registry",
    "dijit/form/Button","dijit/form/Textarea", "dojo/domReady!"],

function(Map, Scalebar, FeatureLayer,Legend, arrayUtils, parser, BorderContainer, ContentPane, AccordionContainer, InfoTemplate, domConstruct,
        Locator,Graphic,SimpleMarkerSymbol,Font,TextSymbol,Font,TextSymbol,Color,number,dom,registry, Button, Textarea){

我的按钮事件监听器:

 registry.byId("locate").on("click", locate);

但是,我收到此错误消息:

Uncaught TypeError: Object function (){var c=arguments,d=c,f=c[0],g,e;e=a.length;var h;if(!(this instanceof c.callee))return v(c);
if(b&&(f&&f.preamble||this.preamble)){h=Array(a.length);h[0]=c;for(g=0;;){if(f=c[0])(f=f.preamble)&&(c=f.apply(this,c)||c);f=a[g].prototype;(f=f.hasOwnProperty("preamble")&&f.preamble)&&(c=f.apply(this,c)||c);if(++g==e)break;h[g]=c}}for(g=e-1;0<=g;--g)f=a[g],(f=(e=f._meta)?e.ctor:f)&&f.apply(this,h?h[g]:c);(f=this.postscript)&&f.apply(this,d)} has no method 'byId'

我的JsFiddle:enter link description here

任何指南?提前谢谢。

1 个答案:

答案 0 :(得分:1)

这是一个有效的jsfiddle,你正在做的问题是你错误地添加了Font, TextSymbol两次回调,这将与注册表回调冲突

require(["esri/map", "esri/dijit/Scalebar", "esri/layers/FeatureLayer", "esri/dijit/Legend", "dojo/_base/array", "dojo/parser", "dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dijit/layout/AccordionContainer", "esri/InfoTemplate", "dojo/dom-construct",
    "esri/tasks/locator", "esri/graphic", "esri/symbols/SimpleMarkerSymbol", "esri/symbols/Font", "esri/symbols/TextSymbol", "esri/Color", "dojo/number", "dojo/dom", "dijit/registry",
    "dijit/form/Button", "dijit/form/Textarea", "dojo/domReady!"],

function (Map, Scalebar, FeatureLayer, Legend, arrayUtils, parser, BorderContainer, ContentPane, AccordionContainer, InfoTemplate, domConstruct,
Locator, Graphic, SimpleMarkerSymbol, Font, TextSymbol, Font, TextSymbol, Color, number, dom, registry) {