⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 domwidget.js

📁 dojo与json创建无限级树的时候,当在父结点下添加了一个新结点,我怎么让父亲结点重新调用json加载一下子结点内容.
💻 JS
📖 第 1 页 / 共 2 页
字号:
	templateNode: null,	templateString: null,	templateCssString: null,	preventClobber: false,	domNode: null, // this is our visible representation of the widget!	containerNode: null, // holds child elements	// Process the given child widget, inserting it's dom node as a child of our dom node	// FIXME: should we support addition at an index in the children arr and	// order the display accordingly? Right now we always append.	addChild: function(widget, overrideContainerNode, pos, ref, insertIndex){		if(!this.isContainer){ // we aren't allowed to contain other widgets, it seems			dojo.debug("dojo.widget.DomWidget.addChild() attempted on non-container widget");			return null;		}else{			this.addWidgetAsDirectChild(widget, overrideContainerNode, pos, ref, insertIndex);			this.registerChild(widget, insertIndex);		}		return widget;	},		addWidgetAsDirectChild: function(widget, overrideContainerNode, pos, ref, insertIndex){		if((!this.containerNode)&&(!overrideContainerNode)){			this.containerNode = this.domNode;		}		var cn = (overrideContainerNode) ? overrideContainerNode : this.containerNode;		if(!pos){ pos = "after"; }		if(!ref){ 			// if(!cn){ cn = document.body; }			if(!cn){ cn = document.body; }			ref = cn.lastChild; 		}		if(!insertIndex) { insertIndex = 0; }		widget.domNode.setAttribute("dojoinsertionindex", insertIndex);		// insert the child widget domNode directly underneath my domNode, in the		// specified position (by default, append to end)		if(!ref){			cn.appendChild(widget.domNode);		}else{			// FIXME: was this meant to be the (ugly hack) way to support insert @ index?			//dojo.dom[pos](widget.domNode, ref, insertIndex);			// CAL: this appears to be the intended way to insert a node at a given position...			if (pos == 'insertAtIndex'){				// dojo.debug("idx:", insertIndex, "isLast:", ref === cn.lastChild);				dojo.dom.insertAtIndex(widget.domNode, ref.parentNode, insertIndex);			}else{				// dojo.debug("pos:", pos, "isLast:", ref === cn.lastChild);				if((pos == "after")&&(ref === cn.lastChild)){					cn.appendChild(widget.domNode);				}else{					dojo.dom.insertAtPosition(widget.domNode, cn, pos);				}			}		}	},	// Record that given widget descends from me	registerChild: function(widget, insertionIndex){		// we need to insert the child at the right point in the parent's 		// 'children' array, based on the insertionIndex		widget.dojoInsertionIndex = insertionIndex;		var idx = -1;		for(var i=0; i<this.children.length; i++){			if (this.children[i].dojoInsertionIndex < insertionIndex){				idx = i;			}		}		this.children.splice(idx+1, 0, widget);		widget.parent = this;		widget.addedTo(this);				// If this widget was created programatically, then it was erroneously added		// to dojo.widget.manager.topWidgets.  Fix that here.		delete dojo.widget.manager.topWidgets[widget.widgetId];	},	removeChild: function(widget){		// detach child domNode from parent domNode		dojo.dom.removeNode(widget.domNode);		// remove child widget from parent widget		return dojo.widget.DomWidget.superclass.removeChild.call(this, widget);	},	getFragNodeRef: function(frag){		if( !frag || !frag["dojo:"+this.widgetType.toLowerCase()] ){			dojo.raise("Error: no frag for widget type " + this.widgetType +				", id " + this.widgetId + " (maybe a widget has set it's type incorrectly)");		}		return (frag ? frag["dojo:"+this.widgetType.toLowerCase()]["nodeRef"] : null);	},		// Replace source domNode with generated dom structure, and register	// widget with parent.	postInitialize: function(args, frag, parentComp){		var sourceNodeRef = this.getFragNodeRef(frag);		// Stick my generated dom into the output tree		//alert(this.widgetId + ": replacing " + sourceNodeRef + " with " + this.domNode.innerHTML);		if (parentComp && (parentComp.snarfChildDomOutput || !sourceNodeRef)){			// Add my generated dom as a direct child of my parent widget			// This is important for generated widgets, and also cases where I am generating an			// <li> node that can't be inserted back into the original DOM tree			parentComp.addWidgetAsDirectChild(this, "", "insertAtIndex", "",  args["dojoinsertionindex"], sourceNodeRef);		} else if (sourceNodeRef){			// Do in-place replacement of the my source node with my generated dom			if(this.domNode && (this.domNode !== sourceNodeRef)){				var oldNode = sourceNodeRef.parentNode.replaceChild(this.domNode, sourceNodeRef);			}		}		// Register myself with my parent, or with the widget manager if		// I have no parent		// TODO: the code below erroneously adds all programatically generated widgets		// to topWidgets (since we don't know who the parent is until after creation finishes)		if ( parentComp ) {			parentComp.registerChild(this, args.dojoinsertionindex);		} else {			dojo.widget.manager.topWidgets[this.widgetId]=this;		}		// Expand my children widgets		if(this.isContainer){			//alert("recurse from " + this.widgetId);			// build any sub-components with us as the parent			var fragParser = dojo.widget.getParser();			fragParser.createSubComponents(frag, this);		}	},	// method over-ride	buildRendering: function(args, frag){		// DOM widgets construct themselves from a template		var ts = dojo.widget._templateCache[this.widgetType];		if(				(!this.preventClobber)&&(				(this.templatePath)||				(this.templateNode)||				(					(this["templateString"])&&(this.templateString.length) 				)||				(					(typeof ts != "undefined")&&( (ts["string"])||(ts["node"]) )				)			)		){			// if it looks like we can build the thing from a template, do it!			this.buildFromTemplate(args, frag);		}else{			// otherwise, assign the DOM node that was the source of the widget			// parsing to be the root node			this.domNode = this.getFragNodeRef(frag);		}		this.fillInTemplate(args, frag); 	// this is where individual widgets											// will handle population of data											// from properties, remote data											// sets, etc.	},	buildFromTemplate: function(args, frag){		// var start = new Date();		// copy template properties if they're already set in the templates object		// dojo.debug("buildFromTemplate:", this);		var avoidCache = false;		if(args["templatecsspath"]){			args["templateCssPath"] = args["templatecsspath"];		}		if(args["templatepath"]){			avoidCache = true;			args["templatePath"] = args["templatepath"];		}		dojo.widget.fillFromTemplateCache(	this, 											args["templatePath"], 											args["templateCssPath"],											null,											avoidCache);		var ts = dojo.widget._templateCache[this.widgetType];		if((ts)&&(!avoidCache)){			if(!this.templateString.length){				this.templateString = ts["string"];			}			if(!this.templateNode){				this.templateNode = ts["node"];			}		}		var matches = false;		var node = null;		// var tstr = new String(this.templateString); 		var tstr = this.templateString; 		// attempt to clone a template node, if there is one		if((!this.templateNode)&&(this.templateString)){			matches = this.templateString.match(/\$\{([^\}]+)\}/g);			if(matches) {				// if we do property replacement, don't create a templateNode				// to clone from.				var hash = this.strings || {};				// FIXME: should this hash of default replacements be cached in				// templateString?				for(var key in dojo.widget.defaultStrings) {					if(dojo.lang.isUndefined(hash[key])) {						hash[key] = dojo.widget.defaultStrings[key];					}				}				// FIXME: this is a lot of string munging. Can we make it faster?				for(var i = 0; i < matches.length; i++) {					var key = matches[i];					key = key.substring(2, key.length-1);					var kval = (key.substring(0, 5) == "this.") ? dojo.lang.getObjPathValue(key.substring(5), this) : hash[key];					var value;					if((kval)||(dojo.lang.isString(kval))){						value = (dojo.lang.isFunction(kval)) ? kval.call(this, key, this.templateString) : kval;						tstr = tstr.replace(matches[i], value);					}				}			}else{				// otherwise, we are required to instantiate a copy of the template				// string if one is provided.								// FIXME: need to be able to distinguish here what should be done				// or provide a generic interface across all DOM implementations				// FIMXE: this breaks if the template has whitespace as its first 				// characters				// node = this.createNodesFromText(this.templateString, true);				// this.templateNode = node[0].cloneNode(true); // we're optimistic here				this.templateNode = this.createNodesFromText(this.templateString, true)[0];				if(!avoidCache){					ts.node = this.templateNode;				}			}		}		if((!this.templateNode)&&(!matches)){ 			dojo.debug("weren't able to create template!");			return false;		}else if(!matches){			node = this.templateNode.cloneNode(true);			if(!node){ return false; }		}else{			node = this.createNodesFromText(tstr, true)[0];		}		// recurse through the node, looking for, and attaching to, our		// attachment points which should be defined on the template node.		this.domNode = node;		// dojo.profile.start("attachTemplateNodes");		this.attachTemplateNodes(this.domNode, this);		// dojo.profile.end("attachTemplateNodes");				// relocate source contents to templated container node		// this.containerNode must be able to receive children, or exceptions will be thrown		if (this.isContainer && this.containerNode){			var src = this.getFragNodeRef(frag);			if (src){				dojo.dom.moveChildren(src, this.containerNode);			}		}	},	attachTemplateNodes: function(baseNode, targetObj){		if(!targetObj){ targetObj = this; }		return dojo.widget.attachTemplateNodes(baseNode, targetObj, 					dojo.widget.getDojoEventsFromStr(this.templateString));	},	fillInTemplate: function(){		// dojo.unimplemented("dojo.widget.DomWidget.fillInTemplate");	},		// method over-ride	destroyRendering: function(){		try{			delete this.domNode;		}catch(e){ /* squelch! */ }	},	// FIXME: method over-ride	cleanUp: function(){},		getContainerHeight: function(){		dojo.unimplemented("dojo.widget.DomWidget.getContainerHeight");	},	getContainerWidth: function(){		dojo.unimplemented("dojo.widget.DomWidget.getContainerWidth");	},	createNodesFromText: function(){		dojo.unimplemented("dojo.widget.DomWidget.createNodesFromText");	}});

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -