javascript - 填充 dojo dijit 组合框

标签 javascript combobox dojo

我有 dijit 组合框,在 cust.Html 页面中声明如下:

<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 和 dijit 非常陌生,因此度过了一段时间。有人可以指导我,因为我在下面的代码中做错了什么。

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;
    });

提前谢谢

最佳答案

据我所知,您从未在 postCreate 函数中定义 self=this 。您是否在小部件实例化阶段的其他地方定义了 self?

我还注意到您将模板命名为“custTemplate”,并使用“searchTemplate”来定义 templateString。

我已经在这个 fiddle 上制作了您的代码的精简版本: http://jsfiddle.net/n4jF7/

我唯一能想到的是如果你没有将 parseOnLoad 设置为 true:

parseOnLoad: true

或者如果您没有调用 parser.parse 来解析模板。

关于javascript - 填充 dojo dijit 组合框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23258996/

相关文章:

javascript - 使用控制比例线保存 map

javascript - 我想通过单击按钮来更新此 d3.js 条形图上的数据。 (点击)

c# - WPF/C# - 绑定(bind)列表 <string> 到组合框

javascript - 正则表达式匹配 Richtext 中的 uri 模式

javascript - 键绑定(bind)触发其 onclick 功能的按钮

建筑道场离开层文件与 "//>>built"

javascript - Dojo 折线图上的自定义标记/工具提示

json - DOJO json布局结构不起作用

c# - comboBox.comboSpec.SelectedItem.ToString() 没有给出正确的值

javascript - jquery UI 组合框 ONCHANGE 不起作用