单击清除按钮后,它将弹出警报,并且在this.gridQuery.value中不显示任何内容,但是gridQuery输入字段本身不反映更改。任何想法?

define([
    "dojo/_base/declare",
    "dojo/request",
    "dijit/_WidgetBase",
    "dijit/_TemplatedMixin",
    "dijit/_WidgetsInTemplateMixin"
], function(declare, request, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin){
    return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
        //  set our template
        templateString: '<div>' +
        'Search: <div id="gridQuery" data-dojo-props="intermediateChanges: true" data-dojo-attach-event="onChange: search" data-dojo-attach-point="gridQuery" data-dojo-type="dijit/form/TextBox"></div> ' +
        '<button data-dojo-attach-point="gridClear" data-dojo-attach-event="onclick: clear">Clear</button>' +
        '<div data-dojo-attach-point="gridText"></div>'
        + '</div>',

        clear: function() {
            this.gridQuery.value = "";
            alert("Should be empty: " + this.gridQuery.value);
        },

        search: function() {
            this.gridText.innerHTML = this.gridQuery.value;
        },

        postCreate: function() {

        }
    });
});

最佳答案

您没有看到任何效果,因为您没有正确设置Dijit小部件的值。

代替:

this.gridQuery.value = '';


尝试:

this.gridQuery.set('value', '');


由于没有完全跨浏览器的方式来查看更改的属性,因此Dijit的getset API允许围绕属性的检索和修改实现自定义逻辑,并使对watch的更改的反应微不足道。也一样

07-24 17:20
查看更多