我有一个下面的情况。我有一个模型A,它具有以下属性: id,int,name,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模板解析器来实现此目的。但是,如果你尝试这样做,那么你最终会得到讨厌的lister,在format row中,你无论如何都会尝试用来自其他lister的输出替换特定的标签,实际上你必须销毁它来避免运行时内存溢出。
有什么建议吗?
附注:上面的代码没有经过测试,只是展示了概念
谢谢!
发布于 2012-07-07 02:24:29
好了,正确的时机已经到来,适当的附加组件已经创建。要使用它,请将您的附加组件和atk4更新为最新版本,并按照本文了解如何使用。
http://www.ambienttech.lv/blog/2012-07-06/tree_view_in_agile_toolkit.html
发布于 2011-12-31 21:08:49
根据Jancha的评论
好的,在花了一些时间研究可能的选项之后,我发现在这种情况下最容易做的事情就是使用上面提到的例子。使其更本地化的唯一方法是为节点使用外部模板,并使用smite和clone region + render将html移到模板之外。除此之外,传统lister的使用似乎不够有效。所以,atk4的朋友们,继续使用查询树视图插件并创建合适的后端吧!那会很酷的。谢谢,j
。
https://stackoverflow.com/questions/7250404
复制相似问题