(on Saturday, 18 October 2008, 05:59 PM +0200):
> I have looked into the code of Zend_Dojo_View_Helper_Dojo_Container, and I
> think it is possible. The theory is simple:
>
> First I will have to get the Dojo modules that are required, by the getModules
> () method. Those modules I can give to Zend_Json which puts them into a JSON
> array. Then, the JavaScript will loop trough all those modules and executes
> dojo.require() statements for each of them. Also, I can use the
> getOnloadActions() method to retrieve the scripts for that, which I will push
> into my JSON response, loop trough them in Javascript and use eval() to execute
> them. The same I can do with the HeadScript and InlineScript helpers.
If you can manage it, please write up a tutorial showing how you
accomplished it.
The problem I alluded to is that Javascript will not execute <script>
tags returned by XHR requests. You can certainly write a handler for
JSON responses, however, that could do as you suggest; the difficulty
there would be if you want to mix HTML and JS. Additionally, you may
have some issues with encoding JS to insert into JSON until we get JS
expression support added to Zend_Json (this proposal is up for review
now, however, and may be included for 1.7.0).
> Matthew Weier O'Phinney schreef:
>
> -- Pieter Kokx <pieter@kokx.nl> wrote
> (on Saturday, 18 October 2008, 04:39 PM +0200):
>
>
> Currently I am busy with a project that loads every page with an AJAX
> request. But that is giving me a problem with Zend_Dojo. When I am using
> Zend_Form, it will render the Form correctly, but it doesn't load the
> Dijit form widgets. It is because I can't execute the dojo.require()
> statements in the AJAX requests. Currently, I am giving some JavaScript
> with the AJAX response, but I don't know how to retrieve the
> dojo.require() and onload statements from the dojo view helper.
>
> Does anybody know how I should take this problem and get the
> dojo.require() and onload statements from the Dojo view helper, so I can
> include them in the AJAX response and execute them on the client side?
>
>
>
> You can't, unfortunately; it's a limitation of Javascript.
>
> The way I tackled it with the pastebin demonstration application was to
> create a Dojo layer that performs all the dojo.require statements I
> need; this also makes it trivial to create a custom build later to speed
> the entire application up.
>
> You can see the build file here:
>
> http://github.com/weierophinney/pastebin/tree/master/public/js-src/paste/layer.js
>
> The important aspect is everything up to the first dojo.addOnLoad()
> statement. If you pay attention to it, basically I'm requiring
> everything I may possibly need in any XHR requests I make, as well as
> the requires necessary for the initial page load. When you create a
> custom build with this layer file, all those will get compiled and
> in-lined to a single file -- making for a concise, single file with all
> functionality.
>
>
>
>
--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/
没有评论:
发表评论