X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=Roo%2FJsonView.js;h=4d9513c4b8302ed88dc65b99d08bc42466d713b7;hb=75cbc4ce04c9c01ac47671cb01320ce699128d00;hp=fdc8dc7f846a3851f568bde1cd4026ae5ae4c3fb;hpb=320928dff6f6f852656c13002278b82309a85bc8;p=roojs1 diff --git a/Roo/JsonView.js b/Roo/JsonView.js index fdc8dc7f84..4d9513c4b8 100644 --- a/Roo/JsonView.js +++ b/Roo/JsonView.js @@ -14,10 +14,12 @@ * @extends Roo.View * Shortcut class to create a JSON + {@link Roo.UpdateManager} template view. Usage:

-var view = new Roo.JsonView("my-element",
-    '<div id="{id}">{foo} - {bar}</div>', // auto create template
-    { multiSelect: true, jsonRoot: "data" }
-);
+var view = new Roo.JsonView({
+    container: "my-element",
+    tpl: '<div id="{id}">{foo} - {bar}</div>', // auto create template
+    multiSelect: true, 
+    jsonRoot: "data" 
+});
 
 // listen for node click?
 view.on("click", function(vw, index, node, e){
@@ -35,7 +37,9 @@ var tpl = new Roo.Template(
     "</div><hr />"
 );
 
-var moreView = new Roo.JsonView("entry-list", tpl, {
+var moreView = new Roo.JsonView({
+    container :  "entry-list", 
+    template : tpl,
     jsonRoot: "posts"
 });
 moreView.on("beforerender", this.sortEntries, this);
@@ -45,16 +49,20 @@ moreView.load({
     text: "Loading Blog Entries..."
 });
 
+* +* Note: old code is supported with arguments : (container, template, config) +* +* * @constructor * Create a new JsonView - * @param {String/HTMLElement/Element} container The container element where the view is to be rendered. - * @param {Template} tpl The rendering template + * * @param {Object} config The config object + * */ -Roo.JsonView = function(container, tpl, config){ +Roo.JsonView = function(config, depreciated_tpl, depreciated_config){ - Roo.JsonView.superclass.constructor.call(this, container, tpl, config); + Roo.JsonView.superclass.constructor.call(this, config, depreciated_tpl, depreciated_config); var um = this.el.getUpdateManager(); um.setRenderer(this); @@ -88,8 +96,7 @@ Roo.JsonView = function(container, tpl, config){ }; Roo.extend(Roo.JsonView, Roo.View, { /** - * The root property in the loaded JSON object that contains the data - * @type {String} + * @type {String} The root property in the loaded JSON object that contains the data */ jsonRoot : "", @@ -141,15 +148,20 @@ Roo.extend(Roo.JsonView, Roo.View, { um.update.apply(um, arguments); }, + // note - render is a standard framework call... + // using it for the response is really flaky... - it's called by UpdateManager normally, except when called by the XComponent/addXtype. render : function(el, response){ + this.clearSelections(); this.el.update(""); var o; try{ - o = Roo.util.JSON.decode(response.responseText); - if(this.jsonRoot){ - - o = /** eval:var:o */ eval("o." + this.jsonRoot); + if (response != '') { + o = Roo.util.JSON.decode(response.responseText); + if(this.jsonRoot){ + + o = o[this.jsonRoot]; + } } } catch(e){ }