paul.zorn-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Aug-10 18:52 UTC
Using Prototype Templates
I put together this simple html file. It works good. But, I am still
fairly new to Prototype and want to get the best result from it. I was
wanting to use the template function. I based this on a example from
the api documentation. But was wondering if using the each function is
the proper way to do this. I setup the JSON based on the way my Ajax
returns results.
<html>
<head>
<title>Test Page</title>
<script src="http://www.prototypejs.org/assets/2007/6/20/
prototype.js"></script>
<script>
function printConversion() {
var conversion = {
amount : 3,
convert : [
{from: ''meters'', to:
''feet'', factor: 3.28},
{from: ''kilojoules'', to:
''BTUs'', factor:
0.9478},
{from: ''megabytes'', to:
''gigabytes'', factor:
1024}
]
};
console.log(conversion);
// the template
var tmpl = new Template(''<pre>Multiply by #{factor}
to
convert from #{from} to #{to}.</pre>'');
var formatted = '''';
//let''s format each object
conversion.convert.each( function(conv) {
formatted += tmpl.evaluate(conv);
});
console.log(formatted);
$(''template_div'').update(formatted);
}
</script>
</head>
<body>
<input type="button" value="Conversion"
onclick="printConversion();" / ><br />
<div id="template_div"></div>
</body>
</html>
Thank you for the help. And also to the developers of prototype, Thank
You for this wonderful piece of software.
Paul Zorn
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---