开发者

Items in CheckboxGroup are for some reason using the same Manager

OK, here it is a small snippet of code (ExtJs 4):

    var TestA = function() {}
    TestA.prototype.createCheckboxes = function() {
    var items = [
        {boxLabel: "A", inputValue: "A", name: "smthng"},
        {boxLabel: "B", inputValue: "B", name: "smthng"}
    ];

    var chgroup = new Ext.form.CheckboxGroup({items:items})
    return chgroup;    
  }

  var开发者_如何转开发 a = new TestA().createCheckboxes().items.get(0).getManager();
  var b = new TestA().createCheckboxes().items.get(0).getManager();
  console.log(a, b, a == b)

As far as I can see, we are creating different instances of Ext.form.CheckboxGroup. Nevertheless, inspecting shows that created items are using same manager. Is it intentional and how can I get rid of such behaviour? Since I want to have "different" checkbox groups not affecting each other (loadRecords on one form affects another)


This is intentional. CheckboxManager is a singleton and nothing more than a "collection of all checkboxes in your DOM" with some wrapper functions

To achieve what you want (activity in one group should not affect others) you will have to make sure that the checkbox name attributes are distinct between your various checkbox groups.

i.e. If group A has checkbox(es) "smthng", group B can have "smthng else" but not "smthng".

(This also makes sense from design perspective since if they have the same name, there is really no distinction between "smthng" in group A and "smthng" in group B.)


Try this:

  var a = new TestA().createCheckboxes().items.get(0);
  var b = new TestA().createCheckboxes().items.get(0);
  console.log(a, b, a === b);

  var c = new TestA().createCheckboxes().items.length;
  var d = new TestA().createCheckboxes().items.length;
  console.log(c, d);

As Ext.form.CheckboxManager is a private utility class for managing all Ext.form.field.Checkbox fields grouped by name. (from ExtJS 4.0.1 docs), i think you will not have any problems you think about.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜