How to disable multiple selection of nodes in dijit.Tree?
http://stackoverflow.com/questions/12261723/how-to-disable-multiple-selection-of-nodes-in-dijit-tree
by phusick
HTML
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.8/dijit/themes/claro/claro.css">
<script src="http://amd.egoworx.com/jsfiddle-dojo-require.js"></script>
<script type="data/json" id="earth">
[
{ id: "earth", name:"The earth", type:"planet", population: "6 billion"},
{ id: "AF", name:"Africa", type:"continent", population:"900 million", area: "30,221,532 sq km",
timezone: "-1 UTC to +4 UTC", parent: "earth"},
{ id: "EG", name:"Egypt", type:"country", parent: "AF" },
{ id: "KE", name:"Kenya", type:"country", parent: "AF" },
{ id: "Nairobi", name:"Nairobi", type:"city", parent: "KE" },
{ id: "Mombasa", name:"Mombasa", type:"city", parent: "KE" },
{ id: "SD", name:"Sudan", type:"country", parent: "AF" },
{ id: "Khartoum", name:"Khartoum", type:"city", parent: "SD" },
{ id: "AS", name:"Asia", type:"continent", parent: "earth" },
{ id: "CN", name:"China", type:"country", parent: "AS" },
{ id: "IN", name:"India", type:"country", parent: "AS" },
{ id: "RU", name:"Russia", type:"country", parent: "AS" },
{ id: "MN", name:"Mongolia", type:"country", parent: "AS" },
{ id: "OC", name:"Oceania", type:"continent", population:"21 million", parent: "earth"},
{ id: "AU", name:"Australia", type:"country", population:"21 million", parent: "OC"},
{ id: "EU", name:"Europe", type:"continent", parent: "earth" },
{ id: "DE", name:"Germany", type:"country", parent: "EU" },
{ id: "FR", name:"France", type:"country", parent: "EU" },
{ id: "ES", name:"Spain", type:"country", parent: "EU" },
{ id: "IT", name:"Italy", type:"country", parent: "EU" },
{ id: "NA", name:"North America", type:"continent", parent: "earth" },
{ id: "MX", name:"Mexico", type:"country", population:"108 million", area:"1,972,550 sq km",
parent: "NA" },
{ id: "Mexico City", name:"Mexico City",...
CSS
html, body {
width: 100%;
height: 100%;
}
JavaScript
require([
"dojo/_base/window",
"dojo/dom",
"dojo/store/Memory",
"dojo/store/Observable",
"dijit/tree/ObjectStoreModel",
"dijit/Tree",
"dojo/domReady!"
], function(
win,
dom,
Memory,
Observable,
ObjectStoreModel,
Tree,
_dndSelector,
dndSource
) {
var store = new Memory({
data: eval(dom.byId("earth").textContent)
});
store.getChildren = function(object){
return this.query({parent: this.getIdentity(object)});
};
store = new Observable(store);
var model = new ObjectStoreModel({
store: store,
query: {id: "earth"}
});
var tree = new dijit.Tree({
id: "tree1",
model: model,
persist: false
}).placeAt(win.body());
tree.dndController.singular = true;
});