webgui/www/extras/yui-ext/docs/overview-summary-JSONDataModel.js.html
JT Smith 4f68a0933c added YUI and YUI-ext
fixed the resizable text area with IE problem
fixed the ad space with IE problem
merged the 7.2.0 and 7.1.4 change logs
2006-11-07 23:15:57 +00:00

138 lines
4.6 KiB
HTML

<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
<html>
<head>
<title>
Overview
</title>
<link rel ="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script>
function asd() {
parent.document.title="JSONDataModel.js Overview";
}
</script>
</head>
<body bgcolor="white" onload="asd();" style="margin:15px;">
<center>
<h2>JSONDataModel.js</h2>
</center>
<h4>Summary</h4>
<p>
</p>
<table border="1" cellpadding="3" cellspacing="0" width="100%">
<tr bgcolor="#CCCCFF" class="TableHeadingColor">
<td colspan="2" class="title-cell">
<b>Class Summary</b>
</td>
</tr>
<tr bgcolor="white" class="TableRowColor">
<td width="15%"><b><a href="YAHOO.ext.grid.JSONDataModel.html">YAHOO.ext.grid.JSONDataModel</a></b></td>
<td>This is an implementation of a DataModel used by the Grid.</td>
</tr>
</table>
<hr/>
<!-- ========== METHOD SUMMARY =========== -->
<!-- ========== END METHOD SUMMARY =========== -->
<pre class="sourceview">
<span class="comment">/**
* <span class="attrib">@class</span>
* This is an implementation of a DataModel used by the Grid. It works
* with JSON data.
* &lt;br&gt;Example schema:
* &lt;pre&gt;&lt;code&gt;
* var schema = {
* root: 'Results.Result',
* id: 'ASIN',
* fields: ['Author', 'Title', 'Manufacturer', 'ProductGroup']
* };
* &lt;/code&gt;&lt;/pre&gt;
* <span class="attrib">@extends</span> YAHOO.ext.grid.LoadableDataModel
* <span class="attrib">@constructor</span>
*/</span>
YAHOO.ext.grid.JSONDataModel = <span class="reserved">function</span>(schema){
YAHOO.ext.grid.JSONDataModel.superclass.constructor.call(<span class="reserved">this</span>, YAHOO.ext.grid.LoadableDataModel.JSON);
<span class="comment">/**<span class="attrib">@private</span>*/</span>
<span class="reserved">this</span>.schema = schema;
};
YAHOO.extendX(YAHOO.ext.grid.JSONDataModel, YAHOO.ext.grid.LoadableDataModel);
<span class="comment">/**
* Overrides loadData in LoadableDataModel to process JSON data
* <span class="attrib">@param</span> {Object} data The JSON object to load
* <span class="attrib">@param</span> {Function} callback
*/</span>
YAHOO.ext.grid.JSONDataModel.<span class="reserved">prototype</span>.loadData = <span class="reserved">function</span>(data, callback, keepExisting){
var idField = <span class="reserved">this</span>.schema.id;
var fields = <span class="reserved">this</span>.schema.fields;
var rowData = [];
try{
var root = eval(<span class="literal">'data.'</span> + <span class="reserved">this</span>.schema.root);
<span class="reserved">for</span>(var i = 0; i &lt; root.length; i++){
var node = root[i];
var colData = [];
colData.node = node;
colData.id = node[idField] || String(i);
<span class="reserved">for</span>(var j = 0; j &lt; fields.length; j++) {
var val = node[fields[j]] || <span class="literal">""</span>;
<span class="reserved">if</span>(<span class="reserved">this</span>.preprocessors[j]){
val = <span class="reserved">this</span>.preprocessors[j](val);
}
colData.push(val);
}
rowData.push(colData);
}
<span class="reserved">if</span>(keepExisting !== true){
<span class="reserved">this</span>.removeAll();
}
<span class="reserved">this</span>.addRows(rowData);
<span class="reserved">if</span>(typeof callback == <span class="literal">'function'</span>){
callback(<span class="reserved">this</span>, true);
}
<span class="reserved">this</span>.fireLoadEvent();
}catch(e){
<span class="reserved">this</span>.fireLoadException(e, null);
<span class="reserved">if</span>(typeof callback == <span class="literal">'function'</span>){
callback(<span class="reserved">this</span>, false);
}
}
};
<span class="comment">/**
* Overrides getRowId in DefaultDataModel to return the ID value of the specified node.
* <span class="attrib">@param</span> {Number} rowIndex
* <span class="attrib">@return</span> {Number}
*/</span>
YAHOO.ext.grid.JSONDataModel.<span class="reserved">prototype</span>.getRowId = <span class="reserved">function</span>(rowIndex){
<span class="reserved">return</span> <span class="reserved">this</span>.data[rowIndex].id;
};</pre>
<hr>
<hr>
<font size="-1">
</font>
<div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Sat Oct 14 06:07:10 2006</div>
</body>
</html>