[Helma-user] __defineGetter__

Michael Platzer michael.platzer at knallgrau.at
Fri Mar 30 19:12:20 CEST 2007


Michael Platzer schrieb:
>   HopObject.prototype.__defineGetter__("first", function() { return 
> this.get(0); });
>   HopObject.prototype.__defineSetter__("first", function() { return; });
>   HopObject.prototype.__defineGetter__("last", function() { return 
> this.get(this.count() - 1); });
>   HopObject.prototype.__defineSetter__("last", function() { return; });
>
> This has the nice effect, that i  can do the following with deep macro 
> invocations:
>
>   <% this.comments.first.title | truncate max="100" %>
>   
oops, the above code sample actually does not work. A 'Macro unhandled' 
error is returned. I got mixed up with another solution attempt to my 
problem. sorry for the confusion.

the problem is that i have a collection, and just want to access the 
first element via deep macro invocations. so, let's assume a simple 1:n 
relation between image and comments.

  Image/type.properties
    _comments = collection(Comment)
    _comments.local = IMAGE_ID
    _comments.foreign = COMMENT_F_IMAGE

i then tried to define an object-reference named 'firstComment':
 
  Image/type.properties
    firstComment = object(Comment)
    firstComment.local = IMAGE_ID
    firstComment.foreign = COMMENT_F_IMAGE

But i could not specify a order nor a maxSize, so that i kind of ended 
up with any object, and not the first one. additionally Helma would 
state 'more than one value returned'-messages all the time.

A much nicer solution would be of course if Helma would directly provide 
sthg like

  <% this.comments.first.title %> or <% this.comments.0.title %>
  <% this.comments.1.title %>
  ...
  <% this.comments.last.title %>

Take a look at http://www.blogr.at/sphere/blogs for example. It displays 
a list of Sites, together with the title and text of the latest story, 
and the titles of the second- and third-last story.

Any suggestions for how to solve this problem?

Thanks,
  michi



More information about the Helma-user mailing list