获取一个dojo节点,当我有商店项目ID [英] getting a dojo node when I have the store item id

查看:96
本文介绍了获取一个dojo节点,当我有商店项目ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 dijit.Tree ,它使用JSON填充一个 ItemFileReadStore 。由于我们的设置,每次点击一个树节点时,我需要做一个新的请求。该树正在使用Cookie来记住哪些文件夹已经被扩展了,所以这不是问题。但是我试图将焦点设置为点击的节点。

I have a dijit.Tree that's populated by a ItemFileReadStore using JSON. Because of our setup, I need to do a new request each time a tree node is clicked. The tree is using cookies to remember which folders were expanded and not, so that's not a problem. But I'm trying to set focus to the node that was clicked.

我已经设法从商店模型中获取项目,将其ID设置为参数url:

I've managed to get the item from the store model by setting its id as a parameter in the url:

store.fetchItemByIdentity({identity:openNode, onItem:focusOpenNode(item)});
function focusOpenNode(item) {
    //I've got the item, now how do I get the node so I can do:
    var node = getNodeFromItem(item); //not a real method...
    treeControl.focusNode(node);
}

但我似乎找不到一种方法来获得匹配的节点

but I can't seem to find a way to get the matching node from the item id.

推荐答案

当您创建treeControl时,作为构造函数参数中的一个参数传递或使用dojo。 mixin添加到树小部件中:

When you create the treeControl, pass in as one of the params in the constructor params or use dojo.mixin to add to the tree widget:

/*tree helper function to get the tree node for a store item*/
getNodeFromItem: function (item) {  
    return this._itemNodesMap[item.name[0]];
}

(使用树的商店getAttribute来获取名称这个项目 - 但是这个例子不是抛光的。)

(It would be neater to use the tree's store getAttribute to get the name of the item - but this example is not polished.)

然后你可以这样做:

function focusOpenNode(item) {
    //I've got the item, now how do I get the node so I can do:

    var node = treeControl.getNodeFromItem(item); //now a real method...
    treeControl.focusNode(node);
}

这篇关于获取一个dojo节点,当我有商店项目ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆