Dojo Tree设置默认选中项并且获得它
先上用来生成Tree的JSON数据
[
{ "id": "Root", "name": "资源目录" },
{ "id": "PF", "name": "批发价格", "parent": "Root" },
{ "id": "PF93", "name": "93#", "parent": "PF" },
{ "id": "PF931", "name": "中石油","type":"WholeSale93CNPC","parent": "PF93" },
{ "id": "PF932", "name": "中石化","type":"WholeSale93SINO", "parent": "PF93" },
{ "id": "PF933", "name": "社会单位","type":"WholeSale93Other", "parent": "PF93" },
{ "id": "PF0", "name": "0#", "parent": "PF" },
{ "id": "PF01", "name": "中石油","type":"WholeSale0CNPC", "parent": "PF0" },
{ "id": "PF02", "name": "中石化","type":"WholeSale0SINO", "parent": "PF0" },
{ "id": "PF03", "name": "社会单位","type":"WholeSale0Other", "parent": "PF0" },
{ "id": "LS", "name": "零售价格", "parent": "Root" },
{ "id": "LS93", "name": "93#", "parent": "LS" },
{ "id": "LS931", "name": "中石油","type":"Retail93CNPC", "parent": "LS93" },
{ "id": "LS932", "name": "中石化","type":"Retail93SINO", "parent": "LS93" },
{ "id": "LS933", "name": "社会单位","type":"Retail93Other","parent": "LS93" },
{ "id": "LS0", "name": "0#", "parent": "LS" },
{ "id": "LS01", "name": "中石油", "type":"Retail0CNPC", "parent": "LS0" },
{ "id": "LS02", "name": "中石化", "type":"Retail0SINO", "parent": "LS0" },
{ "id": "LS03", "name": "社会单位", "type":"Retail0Other", "parent": "LS0" }
]
树生成之后,设置批发价格93#中石油为默认选中项。
leftTree.set('paths', [
['Root', 'PF', 'PF93', 'PF931']
]);
leftTree.focusNode(registry.byId("dijit__TreeNode_3"));
leftTree.set("selectedNodes", [registry.byId("dijit__TreeNode_3")]);
currentTreeItem = leftTree.get('selectedItems')[0];
效果图: