Print

Print


On Mar 28, 2010, at 6:22 PM, Jonathan Rochkind wrote:

> Note if it were the Java/ObjectiveC methods we were talking about, as you can see from the documentation, you would not  be able to call  valueForKey("some.key.path") -- you would need to instead use valueForKeyPath() for that.  And something.valueForKeyPath("some.key.path") is no more and no less than:   something.some().key().path()  , it's just a convenience. (in Java letting you avoid the class-casting at every step of invocation; in any language letting you easily pass around method invocation instructions as data, or store them in config files). 



Yes, I have discovered that valueForKeyPath is really the method I want. And yes, it is a part of the iPhone development environment. Here are a few more details.

In Dashcode I have defined a data source from an remote XML file, and the XML looks like this:

   <waters>
     <water>
       <name water_id='79'>Agean Sea at Kos, Greece</name>
       <collectors>
         <collector collector_id='20'>
           <last_name>Calarco</last_name>
         </collector>
       </collectors>
       <description>Pascal collected...</description>
     </water>
     <water>
       <name water_id='37'>Amazon River, Peru</name>
       <collectors>
         <collector collector_id='8'>
           <last_name>Morgan</last_name>
         </collector>
       </collectors>
       <description>Mom collected...</description>
     </water>
   </waters>

I have then bound elements like name, last_name, and description to various interface elements. Through Javascript I have been able to manipulate these elements as well the collector_id attribute. All this works as expected.

Unfortunately, I am unable to access the water_id attribute. While the water_id attribute displays as a part of my data source and list views, whenever I try to actually access the water_id attribute my application crashes as illustrated by the linked screen shot. [1]

To debug the situation I created a button with the following code using the valueForKeyPath, and as you can see I can access other elements and attributes but not the water_id attribute:

 function getID(event)
 {
   // get my data
   var d = dashcode.getDataSource( 'list' );

   // the following code works
   //var r = d.valueForKeyPath( 'selection.collectors.collector.$collector_id' );

   // this code works too
   //var r = d.valueForKeyPath( 'selection.collectors.collector.last_name' );

   // so does this code
   //var r = d.valueForKeyPath( 'selection.name' );

   // why doesn't this code work! water_id is an attribute of the name element
   var r = d.valueForKeyPath( 'selection.name.$water_id' );

   // echo
   alert( r );
 }

What am I doing wrong? Any assistance or pointers would be greatly appreciated.

[1] screen shot - http://infomotions.com/tmp/screen-dump.png

-- 
Eric Lease Morgan