使用 Agile Toolkit 进行递归树渲染

发布于 2024-12-02 10:53:27 字数 970 浏览 1 评论 0原文

我有以下情况。我有一个模型 A,具有以下属性: id 整数 名称 varchar(255) Parent_id int(引用相同的模型 A)。

现在,我需要使用 ModelA 渲染树视图。当然,我可以加载所有数据,按parent_id对其进行正确排序,然后使用传统的字符串粘贴“渲染它”。例如

class Model_A extends Model_Table {
...

function render_branch($nodes, $parent){
    if (!isset($nodes[$parent])){
        return null;
    }
    $out = "<ul>";
    foreach ($nodes[$parent] as $node){
        $out .= "<li>" . $node["name"];
        $out .= $this->render_branch($nodes, $node["id"]);
        $out .= "</li>";
    }
    return $out;
}

function init(){
    parent::init();
    $nodes = array(); // preload from db and arrange so that key = parent and content is array of childs
    $this->template->set("tree", $this->render_branch($nodes, 0));
}

}

,现在,我想使用 atk4 本机 lister/smlite 模板解析器来实现此目的。但是,如果您尝试这样做,那么您最终会得到令人讨厌的列表器,在格式行中,您无论如何都会尝试用其他列表器的输出替换特定标记,实际上您必须破坏以消除运行时内存溢出。

有什么建议吗?

附注 上面的代码未经测试,仅显示概念

,谢谢!

I have a following situation. I have a Model A with following properties:
id int
name varchar(255)
parent_id int (references same Model A).

Now, I need to render Tree View using that ModelA. Of course, I could just load all data, sort it properly by parent_id and "render it" using traditional string sticking. e.g.

class Model_A extends Model_Table {
...

function render_branch($nodes, $parent){
    if (!isset($nodes[$parent])){
        return null;
    }
    $out = "<ul>";
    foreach ($nodes[$parent] as $node){
        $out .= "<li>" . $node["name"];
        $out .= $this->render_branch($nodes, $node["id"]);
        $out .= "</li>";
    }
    return $out;
}

function init(){
    parent::init();
    $nodes = array(); // preload from db and arrange so that key = parent and content is array of childs
    $this->template->set("tree", $this->render_branch($nodes, 0));
}

}

now, I would instead like to use atk4 native lister/smlite template parser for the purpose. but, if you try to do that, then you would end up with nasty lister, where in format row, you would anyway try to substitute the specific tag with output from other lister which in fact you would have to destruct to void runtime memory overflows.

any suggestions?

p.s.
code above is not tested, just shows concept

thanks!

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

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

发布评论

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

评论(2

温柔少女心 2024-12-09 10:53:27

好的,正确的时间已经到来,正确的附加组件已经创建。要使用它,请更新您的附加组件和 atk4,并按照本文了解如何使用。

http://www.ambienttech.lv/blog/2012-07-06 /tree_view_in_agile_toolkit.html

Okay, right time had come and proper add-on has been created. To use it, get your add ons and atk4 up-to-dated and follow this article to get to know how.

http://www.ambienttech.lv/blog/2012-07-06/tree_view_in_agile_toolkit.html

小猫一只 2024-12-09 10:53:27

根据 Jancha 的评论

好吧,在花了一些时间研究可能的选项后,我发现
在这种特殊情况下最简单的事情就是使用上面提到的例子。
使其更加原生的唯一方法是使用外部模板
节点并使用 smite 和克隆区域 + 渲染将 html 移到外部
模板。除此之外,传统列表器的使用似乎并没有
足够高效。所以,atk4 的朋友们,请跟进查询树视图
插件并创建适当的后端!那就太酷了。谢谢,j

As per Jancha's comment

okay, after spending some time looking at possible options, I found that
the easiest thing to do in this particular case was to use above mentioned example.
The only way to make it more native would be to use external template for
nodes and use smite and clone region + render to move html outside t o
template. apart from that, usage of traditional lister did not seem to
be efficient enough. so, atk4 guys, follow up with query tree view
plugin and create proper backend! it would be cool. thanks,j

.

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