0

我是新的 dynatree 用法。除了将每个分支的最后一个孩子显示为 null 之外,一切都很酷且延迟加载。

$("#tree").dynatree({
    title: "Lazy loading sample",
    fx: { height: "toggle", duration: 200 },
    autoFocus: false,

    initAjax: {
        url: "/get_top_level_nodes",
        data: { mode: "funnyMode" }
    },

    onActivate: function(node) {
        $("#echoActive").text("" + node + " (" + node.getKeyPath()+ ")");
    },

    onLazyRead: function(node){
        node.appendAjax({
            url: "/get_children",
            data: { key: node.data.key,mode: "funnyMode"}
            });
    }
});

如果 json 结果不为空,如下所示。它工作正常。杰森:[ { "title": "Node1", "isLazy": true, "key": "BC13B21636CD6D5C"}, { "title": "Node1", "isLazy": true, "key": "BC13B21636CD6D5C"}]

如果 ajax 结果为空[],我将返回为null. null然而我在那个分支中看到了一个子节点。我怎样才能删除这个?如果没有孩子,我不想展示null或任何东西。

4

3 回答 3

1

如果 ajax 结果为空 [],我将返回 null。

您应该返回[];-)

于 2014-03-22T17:55:03.600 回答
0

如果结果是 [] 数组而不是 [ { "title": "Node1", "is Lazy": true, "key": "BC13B21636CD6D5C"}, { "title": "Node1", "is Lazy": true, “关键”:“BC13B21636CD6D5C”}],

如果父母没有孩子,则返回 nil。我在控制器中有格式化方法,用于将子数组格式化为子格式,

于 2014-03-22T18:18:25.600 回答
0

mar10 的回答是正确的。这是我用于使用延迟加载的树的代码。如果没有要返回的子节点,我会回显一个空的 JSON 对象“[]”:

$res = mysql_query($req) or die(mysql_error());
$i=0;
while($cat = mysql_fetch_assoc($res)) {
  $cats[] = $cat;
  $i = 1;
}
if ($i)
  echo json_encode($cats);
else
  echo "[]";
于 2017-01-16T18:03:28.393 回答