PDA

View Full Version : Object as DataSource (PropertyGrid)



macm
2 Jun 2007, 7:29 PM
I am not sure why I can not wrap my head around this... maybe not enough JS experience. I am trying to load a PropertyGrid with a string of values.

This code does not work:


var myDataArray = ["'id':'12'"];
var myData = Ext.data.SimpleStore(myDataArray);
propsGrid.setSource(myData);
propsGrid.render();


This code does work ,but only in design mode... I can not figure out how to incorporate a string of values.


propsGrid.setSource({id:'12'});
propsGrid.render();


I would really like something like this..


var props = 'id:12, name: mark'
propsGrid.setSource(props ); //just throw in my variable.
propsGrid.render();


This is probably simple and I am just overlooking it, help is appreciated!

macm
2 Jun 2007, 8:37 PM
I figured this out. DUH!

I just needed to create a json string with my values in a simple pair... then call eval() on the json string. The solution I cam up with works.. there may be a better way, so suggestions are welcomed.

Here is working code:


var jsonText = "{'id':'12', 'name':'mike'}";
var value = eval( "(" + jsonText + ")" );
propsGrid.setSource(value);
propsGrid.render();

Animal
3 Jun 2007, 12:19 AM
I figured this out. DUH!

I just needed to create a json string with my values in a simple pair... then call eval() on the json string. The solution I cam up with works.. there may be a better way, so suggestions are welcomed.

Here is working code:


var jsonText = "{'id':'12', 'name':'mike'}";
var value = eval( "(" + jsonText + ")" );
propsGrid.setSource(value);
propsGrid.render();


Why create a string containing javascript source code, then interpret it. Why not just create the object you want to create?



value = {id:12, name:'mike'};