[Developers] sandbox.freebase.com weekly update

Tim Sturge tsturge at metaweb.com
Tue Jul 10 19:00:44 UTC 2007


Hi Kirsten,

There's actually three separate cases here:

1) games with an image. The result should look something like

image.result=
{
"id":"#92...."
"type":[{ "name": "Game", 
           "id": "/game/game" 
       }],
"name":"SimCity",
"/common/topic/image":{
	"id":"#92...",
	"timestamp":"2007-06-01T..."
}
}

2) games without an image:

image.result=
{
"id":"#92...."
"type":[{ "name": "Game", 
           "id": "/game/game" 
       }],
"name":"SimCity",
"/common/topic/image":null
}

3) things that aren't there at all (mjt.urlquery.game points to 
something that doesn't exist)

image.result=null

(this is what seems to be causing the error you are seeing)

So you do need to check if image.result['/common/topic/image'] is null 
or not (to catch case 2) but you might also want to check if
image.result itself is null or not (to catch case 3). Of course if 
image.result is null, there's nothing to display at all.

If you're seeing case 3 a lot, it might be interesting to examine the 
"id" field you are getting from mjt.urlquery.game; it should either be 
"#92..." (that is 32 hex digits with a leading # sign) or 
"/wikipedia/en/SimCity" (that is a / separated list of words like an 
absolute UNIX pathname)

I hope this helps,

Tim


Kirsten Jones wrote:
> Hi all,
>
> I'm trying to create an MJT implementation similar to the FMDb, but  
> I'm running into an issue where it's not behaving correctly for me.
>
> I have this, which probably looks suspiciously like the same code  
> from FMDb:
>
> <div mjt.task="image">
> 	mjt.mqlread({
> 		"id":mjt.urlquery.game,
> 		"type":[{}],
> 		"name":null,
> 		"/common/topic/image":({
> 			"id":null,
> 			"timestamp":null,
> 			"optional":true,
> 			"limit":1
> 		})
> 	})
> </div>
>
> <img alt="image" src="#" mjt.src="${mjt.imgurl(image.result['/common/ 
> topic/image'].id, 265, 1000)}" />
>
> For games with an image, this causes the image to appear, but I get  
> an error:
>
> error applying tfunc main() [object Object]
>      TypeError: image.result has no properties
>              										"limit":1
>             									})
>             								})
>             							));
>             __m[__n++]=__ts[52];
> ---174-->  if (image.result['/common/topic/image'].length) {
>             __m[__n++]=__ts[53];
>             __m[__n++]=(mjt.imgurl(image.result['/common/topic/ 
> image'].id, 265, 1000));
>             __m[__n++]=__ts[54];
>             }
>
> For games with no image, I just get the error, no image, and it  
> doesn't display the rest of the stuff.
>
> If I add the logic of <div mjt.if="image.result['/common/topic/ 
> image'].length"> I don't get the picture ever, but I still get the  
> error.
>
> I assume I'm missing something obvious.  Help?
>
> TIA,
>
> Kirsten
>
> _______________________________________________
> Developers mailing list
> Developers at freebase.com
> http://lists.freebase.com/mailman/listinfo/developers
>   



More information about the Developers mailing list