Extjs:(TimeField)重置minValue和maxValue

发布于 2024-10-14 22:35:11 字数 231 浏览 1 评论 0原文

我有一个 ExtJS TimeField,其中使用 setMinValue(...)setMaxValue(...) 仅显示有效时间-元素给用户。这工作得很好,但如何重置 minValuemaxValue 以便用户可以再次看到所有时间元素?

我不想清除该字段,只是再次显示商店中的所有元素。

I have an ExtJS TimeField where I use the setMinValue(...) and setMaxValue(...) to only show the valid time-elements to the user. This works just fine, but how do I reset the minValue and maxValue so that the user can see all the time-elements again?

I don't want to clear the field, just show all the elements from the store again.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

秉烛思 2024-10-21 22:35:11

我没有看到任何“干净”的方法来完成此任务,但我确实有一个临时的解决方法,直到您找到更合适的方法。

尝试将 TimeFieldminValuemaxValue 设置为 undefinednull,然后然后在您的 TimeField 上调用 generateStore()

    // private
    generateStore: function(initial){
        var min = this.minValue || new Date(this.initDate).clearTime(),
            max = this.maxValue || new Date(this.initDate).clearTime().add('mi', 
                        (24 * 60) - 1),
            times = [];

        while(min <= max){
            times.push(min.dateFormat(this.format));
            min = min.add('mi', this.increment);
        }
        this.bindStore(times, initial);
    },

是的,它是一个私有方法,所以通常您不应该使用它,但如果您只是重置 minValue 或 maxValue,通常会调用该方法,所以您'只是跳过了一步。通过将两个属性设置为 null,var min, max = 的声明将等于默认值。您不能通过调用 setMinValue()setMaxValue() 来解决此问题,因为它使用私有方法,尝试从您传递给的值中解析出 Date方法(解析 null 时会失败):

    // private
    setLimit: function(value, isMin, initial){
        var d;
        // will fail here
        if(Ext.isString(value)){
            d = this.parseDate(value);
        // will fail as well
        }else if(Ext.isDate(value)){
            d = value;
        }
        // will never make it here, because 'd' wasn't set above
        if(d){
            var val = new Date(this.initDate).clearTime();
            val.setHours(d.getHours(), d.getMinutes(), d.getSeconds(),
                         d.getMilliseconds());
            this[isMin ? 'minValue' : 'maxValue'] = val;
            if(!initial){
                this.generateStore();
            }
        }
    }

更新:

更简洁的方法是扩展 TimeField 并添加一个 resetMinAndMax 方法来完成上述操作(将 minValue/maxValue 设置为 null,调用生成存储),或在重写中添加该方法。这样您就可以避免在任何地方调用“私有”generateStore()

I don't see any "clean" way to accomplish this, but I do have a temporary workaround until you find something more suitable.

Try setting the TimeField's minValue and maxValue to undefined or null, and then call generateStore() on your TimeField:

    // private
    generateStore: function(initial){
        var min = this.minValue || new Date(this.initDate).clearTime(),
            max = this.maxValue || new Date(this.initDate).clearTime().add('mi', 
                        (24 * 60) - 1),
            times = [];

        while(min <= max){
            times.push(min.dateFormat(this.format));
            min = min.add('mi', this.increment);
        }
        this.bindStore(times, initial);
    },

Yes it is a private method, so normally you shouldn't use it, but the method would normally be called if you simply reset minValue or maxValue, so you're just skipping a step. By setting both properties to null, the declaration for var min, max = will be equal to the default. You can't go about this by calling setMinValue() or setMaxValue() because it uses a private method that attempts to parse a Date out of the value you pass to the methods (it will fail at parsing null):

    // private
    setLimit: function(value, isMin, initial){
        var d;
        // will fail here
        if(Ext.isString(value)){
            d = this.parseDate(value);
        // will fail as well
        }else if(Ext.isDate(value)){
            d = value;
        }
        // will never make it here, because 'd' wasn't set above
        if(d){
            var val = new Date(this.initDate).clearTime();
            val.setHours(d.getHours(), d.getMinutes(), d.getSeconds(),
                         d.getMilliseconds());
            this[isMin ? 'minValue' : 'maxValue'] = val;
            if(!initial){
                this.generateStore();
            }
        }
    }

Update:

A cleaner approach would be to extend TimeField and add a resetMinAndMax method that accomplishes the above (set minValue/maxValue to null, call to generate store), or add the method in an override. That way you can avoid making calls to the "private" generateStore() everywhere.

没有伤那来痛 2024-10-21 22:35:11

你可以用简单的

this.setMinValue(false);

运气

you can use simply

this.setMinValue(false);

good luck

鸩远一方 2024-10-21 22:35:11

extjs 仅重置组件中的属性“值”(如果我没有错的话),好吧,我不知道我的代码是否是更好的方法,但是..像上面的答案一样,我覆盖了重置方法DateField 类使用 Field 类的代码,并添加另外 2 个属性来保留原始值(originalMinValue 和originalMaxValue)。

OriginalMinValue 和originalMaxValue 在我的日期字段的Render 事件上启动。

this.setValue = this.setValue.createSequence(this.updateHidden);
this.originalMinValue = this.minValue;
this.originalMaxValue = this.maxValue;
// this is part of me onRender event code

这就是重写

Ext.override(Ext.form.DateField,{   
originalMinValue : null,
originalMaxValue : null,
reset : function() {                
    this.setValue(this.originalValue);      
    this.setMinValue(this.originalMinValue);
    this.setMaxValue(this.originalMaxValue);
    this.clearInvalid();        
}

})

这样,我们就可以使用组件的重置方法 e 然后将 value、minValue 和 MaxValue 返回到原始值。

抱歉我的英语不好。

The extjs only reset the property "value" from a component(if i'm not wrong), well, i don't know if my code is the better way, but..like the above answer, i overrode the reset method from DateField class using the code of Field class and add a 2 more properties to keep the original values(originalMinValue and originalMaxValue).

the originalMinValue and originalMaxValue are started onRender event of my Date Field.

this.setValue = this.setValue.createSequence(this.updateHidden);
this.originalMinValue = this.minValue;
this.originalMaxValue = this.maxValue;
// this is part of me onRender event code

and that's the override

Ext.override(Ext.form.DateField,{   
originalMinValue : null,
originalMaxValue : null,
reset : function() {                
    this.setValue(this.originalValue);      
    this.setMinValue(this.originalMinValue);
    this.setMaxValue(this.originalMaxValue);
    this.clearInvalid();        
}

})

this way, we can use the component's reset method e then, value, minValue, and MaxValue going back to the originalValue.

sorry for my bad english.

疯狂的代价 2024-10-21 22:35:11

您是否在加载页面时获取时间字段的初始值?如果是这种情况,您应该能够使用FIELD 类的reset() 方法。您应该有权访问它,因为时间字段组件是从 FIELD 扩展而来的。

Are you after the initial values for the timefield when the page is loaded? If that's the case, you should be able to use the reset() method of the FIELD class. You should have access to this since the timefield component is extended from FIELD.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文