Looks like it should work to me, but I don't know because you are very 
specific in your boolean tests. For example:
var blah = 'true'; //the string "true"
blah == true //this is false

elem.isDefault==true //this probably isn't working...

I don't know what getAttribute("default") is returning in your case, but 
say it is a string representation of "true"/"false". If so, change line 
26 of your pastie to:
          isDefault: elem.getAttribute("default") == "true",

Now, in displayTopic, to get the topic use this simplified code:
  var topic = topics.find( topicID ?
    function(elem){ return elem.isDefault } :
    function(elem){ return elem.id == topicID } );

Firefox and Firebug are your friends if there is any doubt as to what 
values you have stored and how they are comparing in your code.

Colin

Vin wrote:
> Dear Colin:
> I took few minutes this morning to modify my code following your
> suggestion,and it works,but not entirely.
> There is a problem in the "displayTopic" function,where and when i use
> the "find" method of prototype's Enumerable object,and i couldn't
> figure it out.Is there anything wrong with my iterator function in
> that "find" method??
> I wrote the "displayTopic" function like this,and the iterator
> function as its nested function:
> The detail code i've pasted to pastie:http://pastie.caboo.se/
> 51571[line 73]
> function displayTopic(topicID){
>   var topic;
>   function iterator(elem){
>     if(topicID==null ||topicID==""){
>       return (elem.isDefault==true)?true:false;
>     }else{
>        return (elem.id==topicID)?true:false;
>     }
>  };
>  //find method here
>  topic=topics.find(iterator);
>  alert(topic.id);//this's for test,it show nothing.
>  alert("hi");//this's for test too,it show "hi"
>  ....
>  ....
> }
>
>    Sincerely bookish Vin.:>
>
>
> >
>
>   


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to