<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>I Can Has Code?!? &#187; Adobe AIR</title>
	<atom:link href="http://icanhascode.com/tag/adobe-air/feed/" rel="self" type="application/rss+xml" />
	<link>http://icanhascode.com</link>
	<description>No, not for you.</description>
	<lastBuildDate>Wed, 17 Jun 2009 07:22:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Code Quickie : ExtJS JsonReader With Mapping Support For Use In AIR</title>
		<link>http://icanhascode.com/2009/05/code-quickie-extjs-jsonreader-with-mapping-support-for-use-in-air/</link>
		<comments>http://icanhascode.com/2009/05/code-quickie-extjs-jsonreader-with-mapping-support-for-use-in-air/#comments</comments>
		<pubDate>Wed, 20 May 2009 07:40:28 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Code Quickie]]></category>
		<category><![CDATA[Adobe AIR]]></category>
		<category><![CDATA[Ext JS]]></category>

		<guid isPermaLink="false">http://icanhascode.com/2009/05/code-quickie-extjs-jsonreader-with-mapping-support-for-use-in-air/</guid>
		<description><![CDATA[So, yesterday I decided to play around with Adobe AIR, which I&#8217;m not familiar with, in conjunction with Ext JS, which I am familiar with.  Overall, if you are familiar with Ext JS on the web, you&#8217;re familiar with it in Adobe AIR &#8230; except for a number of unique issues due to Adobe AIR&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>So, yesterday I decided to play around with Adobe AIR, which I&#8217;m not familiar with, in conjunction with Ext JS, which I am familiar with.  Overall, if you are familiar with Ext JS on the web, you&#8217;re familiar with it in Adobe AIR &#8230; except for a number of unique issues due to Adobe AIR&#8217;s default sandbox, mostly revolving around the sandbox and what you can and can&#8217;t do in it.  Well, I ran into an issue tonight where I needed to use a <strong><em>JsonReader</em></strong> and use <strong><em>Record</em></strong> mappings with dot notation (i.e. binding a field to a child object in the JSON data).  My guess is that, as is the case with <strong><em>eval</em></strong>, <strong><em>new Function(&#8230;)</em></strong>, which is what the default implementation of <strong><em>getJsonAccessor</em></strong> uses, is blocked by the sandbox.  I fixed it by extending the default <strong><em>JsonReader</em></strong> and providing a new implementation of <strong><em>getJsonAccessor</em></strong> using some code I created a while back for form binding in JavaScript.</p>
<pre class="jscript" name="code">JsonReader = Ext.extend(Ext.data.JsonReader, {
    exprToPath: function(expr) {
        var parts = expr.split(".");
        var path = [];
        Ext.each(parts, function(item, index, list) {
            var match = item.match(/([a-zA-Z0-9_]+)\[([^\]]+)\]/);
            if (match)
            {
                path.push(match[1]);
                if (/^\d+$/.test(match[2]))
                    path.push(parseInt(match[2]));
                else
                    path.push(match[2]);
            }
            else
            {
                path.push(item);
            }
        });
        return path;
    },  

    getDataValue: function(o, path) {
        var current = o;
        var rPath = path.slice().reverse();
        while (current &amp;&amp; rPath.length &gt; 0)
        {
            var key = rPath.pop();
            if (typeof current[key] !== &#39;undefined&#39;) current = current[key]; else return null;
        }

        return current;
    },

    getJsonAccessor: function(expr) {
        var self = this;
        var path = this.exprToPath(expr);
        return function(obj) {
            return self.getDataValue(obj, path);
        };
    }
});</pre>
<p>It&#8217;s probably a bit of overkill for what is needed, but it does work well.</p>
]]></content:encoded>
			<wfw:commentRss>http://icanhascode.com/2009/05/code-quickie-extjs-jsonreader-with-mapping-support-for-use-in-air/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.163 seconds -->
