gpt4 book ai didi

properties - Extjs 配置选项与属性

转载 作者:行者123 更新时间:2023-12-01 08:33:04 24 4
gpt4 key购买 nike

Java 类具有用于操作这些属性的属性和方法。 ExtJS 类具有属性、方法和 configOptions
从概念上讲,configOptions 和属性有什么区别?为什么我们两者都需要?

最佳答案

据我了解……

configs - are passed in the constructor, which defines behavior of the class, configs should not be changed at run-time because it will not have any effect, suppose you need to specify a title for the panel then you can add a config e.g. { title : 'some title' } that will be used by panel to set title of the panel at render time, but after that, even if you try to change title, you can't alter the property by simply changing that config option.

properties - are used to store information which is useful for that class, this is normally not passed through constructor but should have getter and setter methods, you can change property at run-time (if setter method is defined) and class object should detect this change, there can be read only properties also which are modified by class object only we shouldn't change it all.

更多信息

Sencha: Properties vs Configs, in the Ext 4 Documentation

My answer to this question is a little simplistic and idealistic. I'm afraid trying to give a full answer that covers all the subtleties is more likely to add to the confusion rather than clarifying the situation.

Config options are used to configure an object when it is created. Trying to set them as properties on the object after it has been instantiated will often have no effect.

Ext.create('Ext.panel.Panel', {
// config options go here
});

An object will have lots of properties but only the ones listed in the Properties section should be considered public properties. While there's nothing to stop you accessing the private properties you should only do it as a last resort, try to use the documented methods to manipulate them instead where possible.

// rendered is a public property used to indicate whether the panel has been rendered
if (panel.rendered) {
// could just do panel.el but that isn't a public property, so use getEl instead
var el = panel.getEl();
...
}

One reason why the lines get blurred is that objects generally copy their configs onto themselves like this:

Ext.apply(this, config);

This results in all the config options becoming private properties, at least initially. Internally classes can then manipulate those properties as appropriate but externally accessing those properties is a breach of encapsulation and should be avoided.

关于properties - Extjs 配置选项与属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15644640/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com