单击按钮时,自定义dojo小部件不会清除文本字段

时间:2015-08-25 14:42:07

标签: javascript dojo

单击清除按钮后,它会弹出警报,并且不会在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() {

        }
    });
});

1 个答案:

答案 0 :(得分:1)

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

而不是:

this.gridQuery.value = '';

尝试:

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

由于没有完全跨浏览器的方式来观察更改属性,因此Dijit的getset API允许围绕属性的检索和修改实现自定义逻辑,以及对watch的变化作出反应也是微不足道的。