我在cust.Html页面中有一个dijit组合框,如下所示:
<div class="CustDijit">
<div class="formContainer">
<div data-dojo-type="dijit.form.Form" data-dojo-attach-point="searchFormDijit">
<table cellspacing="5" style="width:100%; height: 49px;">
<tr>
<td>
<select data-dojo-type="dijit.form.ComboBox" name="state" data-dojo-id="comboBoxID2" id="stateInput" data-dojo-attach-point="idResultItemsCB"/>
<br />
Enter Attribute Value:<input id="searchText" type="text" data-dojo-type="dijit.form.ValidationTextBox" data-dojo-props="name:'searchText',trim:true,required:true,style:'width:100%;'"
/>
</td>
</tr>
</table>
</div>
</div>
</div>
`
现在这个html页面正在js代码中创建为一个小部件,如下所示......它在这里我想填充组合框。我有创建的功能来组合组合框,但因为我是新的dojotoolkit和dijits因此有一个凝灰岩时间..可以请一些人指导我,因为我在下面的代码中做错了。
define([
'dojo/_base/declare',
'dijit/_WidgetBase',
'dijit/_TemplatedMixin',
'dijit/_WidgetsInTemplateMixin',
"dijit/registry",
'dijit/form/Form',
'dijit/form/FilteringSelect',
'dijit/form/ValidationTextBox',
'dijit/form/Button',
"dijit/layout/ContentPane",
"dojo/store/Memory",
"dojo/data/ItemFileReadStore",
'dojox/grid/DataGrid',
'dijit/TooltipDialog',
'esri/tasks/query',
'esri/tasks/QueryTask',
'esri/config',
'dojo/store/Memory',
'dojo/_base/lang',
'dojo/_base/array',
'dojo/text!./Cust/templates/cust.html',
"dojo/parser",
'dijit/form/ComboBox',
"dijit/form/FilteringSelect",
"dojo/domReady!"
], function (declare, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, registry, Form, FilteringSelect, ValidationTextBox, Button, ContentPane, Memory, ItemFileReadStore, DataGrid, TooltipDialog, query, QueryTask, esriConfig, Memory, lang, array, custTemplate, parser, ComboBox, FilteringSelect,dom) {
//anonymous function to load CSS files required for this module
(function () {
var css = [require.toUrl("gis/dijit//css/cust.css")];
var head = document.getElementsByTagName("head").item(0),
link;
for (var i = 0, il = css.length; i < il; i++) {
link = document.createElement("link");
link.type = "text/css";
link.rel = "stylesheet";
link.href = css[i].toString();
head.appendChild(link);
}
parser.parse();
} ());
// Main cust dijit
var Cust = declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin],
{
widgetsInTemplate: true,
templateString: custTemplate,
map: null,
defaultTitle: null,
queryTask: null,
query: null,
map: null,
self: null,
_store1: null,
_selectorOne: null,
postCreate: function () {
this.inherited(arguments);
this.queryTask = new esri.tasks.QueryTask(this.queryTaskURL);
this.query = new esri.tasks.Query();
this.query.outSpatialReference = this.map.spatialReference;
this.query.returnGeometry = true;
this.query.outFields = ["id", "Custname", "Status"];
self.cmboxlayer();
this.populateResultsIntoComboBox(Memory);
},
populateResultsIntoComboBox: function (Memory) {
var stateStore = new Memory({
data: [
{ name: "Alabama", id: "AL" },
{ name: "Alaska", id: "AK" },
{ name: "Arizona", id: "AZ" },
{ name: "Arkansas", id: "AR" },
{ name: "California", id: "CA" },
{ name: "Colorado", id: "CO" },
{ name: "Connecticut", id: "CT" },
{ name: "Delaware", id: "DE" }
]
});
var comboBoxDigit = registry.byId("stateInput");
//on(comboBoxDigit, "change", lang.hitch(this, 'comboBoxSelectionChangedEventHandler'));
comboBoxDigit.store = stateStore;
comboBoxDigit.searchAttr = "title";
comboBoxDigit.set('value', stateStore.data[0].title);
}
});
return Search;
});
提前谢谢
答案 0 :(得分:0)
从我所看到的,你永远不会在postCreate函数中定义self = this。您是否在小部件实例化阶段中将自己定义在其他位置?
我还注意到你命名了你的模板'custTemplate',并使用'searchTemplate'来定义你的templateString。
我已经在这个小提琴上制作了一个简化版本的代码: http://jsfiddle.net/n4jF7/
我唯一能想到的是你没有将parseOnLoad设置为true:
parseOnLoad: true
或者如果你没有调用parser.parse来解析模板。