以编程方式控制 Dojo Accordion

发布于 2024-07-14 03:41:37 字数 1285 浏览 8 评论 0原文

我的页面上有一个 dijit.layout.AccordionContainer,它是在 html 中定义的,并在 dojo 加载时解析页面时创建。

然后,当用户与页面交互时,我使用 Ajax 检索数据并以编程方式填充容器(首先删除现有项目)。

为了简单地说明我的问题,这里有一些不起作用的代码:

   function doit() {
        var accordion = dijit.byId("accordionShell");
        accordion.getChildren().each(function(item) {
            accordion.removeChild(item);
        });
        for (i = 1; i < 5; i++) {
            var d = new dijit.layout.AccordionPane({title:'hello', content:'world'});
            accordion.addChild(d);
        }
    }

这会失败,因为只有手风琴中的第一项可见。 我认为其他的确实存在,但它们不可见,所以你无能为力。

我设法通过以下方式解决这个问题:

  1. 始终确保手风琴中有 1 个项目(所以我从不删除第一个子项)
  2. 更改内容后调用 Accordian.layout()

因此,只要您总是这样,此代码就“有效”想要查看第一项,并且实际上除了第一项之外不展开任何项:

   function doit() {
        var accordion = dijit.byId("accordionShell");
        var i = 0;
        accordion.getChildren().each(function(item) {
            if (i > 0) accordion.removeChild(item);
            i++;
        });
        for (i = 1; i < 5; i++) {
            var d = new dijit.layout.AccordionPane({title:'hello', content:'world'});
            accordion.addChild(d);
        }
        accordion.layout();

    }

我正在使用 Dojo 1.2.0 - 有人知道我做错了什么吗?

I have a dijit.layout.AccordionContainer on my page which is defined in the html and created when dojo parses the page on load.

Then, as the user interacts with the page I use Ajax to retrieve data and programmatically populate the container (removing existing items first).

To illustrate my issue simply, here is some code that doesn't work:

   function doit() {
        var accordion = dijit.byId("accordionShell");
        accordion.getChildren().each(function(item) {
            accordion.removeChild(item);
        });
        for (i = 1; i < 5; i++) {
            var d = new dijit.layout.AccordionPane({title:'hello', content:'world'});
            accordion.addChild(d);
        }
    }

This fails, because only the first item in the accordian is visible. I think the others actually exist, but they are not visible so you can't do anything.

I've managed to get around it by:

  1. Always ensuring there is 1 item in the accordian (so I never remove the first child)
  2. Call accordian.layout() after changing the contents

So, this code "works" as long as you always want to see the first item, and don't actually expand any but the first one:

   function doit() {
        var accordion = dijit.byId("accordionShell");
        var i = 0;
        accordion.getChildren().each(function(item) {
            if (i > 0) accordion.removeChild(item);
            i++;
        });
        for (i = 1; i < 5; i++) {
            var d = new dijit.layout.AccordionPane({title:'hello', content:'world'});
            accordion.addChild(d);
        }
        accordion.layout();

    }

I am using Dojo 1.2.0 - Anyone know what I am doing wrong?

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

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

发布评论

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

评论(3

笑红尘 2024-07-21 03:41:37

如果我没记错的话...你应该这样做...

  pane1half = new dijit.layout.ContentPane({id: "pane1half", title: "hello", content: "world"});

87 Accordion.addChild(pane1half, 1);

If Im not mistaking...you should do...

  pane1half = new dijit.layout.ContentPane({id: "pane1half", title: "hello", content: "world"});

87 accordion.addChild(pane1half, 1);

黎歌 2024-07-21 03:41:37

我相信我发现了一个问题 - Accordian.removeChild() 还不够。 如果你摧毁它,那么行为似乎是正确的。 我不知道你是否必须两者都做,或者单独销毁是否就足够了。

因此,删除现有项目的代码变为:

accordion.getChildren().each(function(item) {
        if(i>0) {
            accordion.removeChild(item);
            item.destroy();
        }
        i++;
});

我正在通过在第一项中添加“帮助信息”来解决此限制...

I believe I found one problem - accordian.removeChild() is not enough. If you destroy it, then the behaviour seems to be correct. I don't know if you have to do both or if destroy by itself is enough.

So, the code to remove existing items becomes:

accordion.getChildren().each(function(item) {
        if(i>0) {
            accordion.removeChild(item);
            item.destroy();
        }
        i++;
});

I'm working around this limitation by having 'help information' in the first item...

桃扇骨 2024-07-21 03:41:37

我每次都会创建一个新的 AccordionContainer,添加 AccordionPane 子项,然后执行以下操作:

oldAccordion.domNode.parentNode.replaceChild(
  newAccordion.domNode,
  oldAccordion.domNode
);

oldAccordion.destroyRecursive();
newAccordion.startup();

I would create a new AccordionContainer each time, add the AccordionPane children, then do:

oldAccordion.domNode.parentNode.replaceChild(
  newAccordion.domNode,
  oldAccordion.domNode
);

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