Hello, the nittro has the same function as nette.ajax.js
$ .nette.ext ({
load: function ()
...
? When I reload the page by ajax, the function from my external JS file not work.
Hi, I'm not sure I understand what you're asking..? If I remember correctly how nette.ajax.js
works, the code snippet you posted would execute the function each time a page is loaded, is that right? In that case you can use the after-update
event of the snippetManager
service. In a JS file included in your main build along with Nittro you'd write something like this:
_context.invoke(function() {
var MyService = _context.extend(function(snippetManager) {
snippetManager.on('after-update', this._handleUpdate.bind(this));
}, {
_handleUpdate: function() {
// your code
}
});
_context.register(MyService, 'MyService');
});
and then you'd add myService: "MyService()!"
to the services
section of your bootstrap
config in Nittro builder (read more about building Nittro here and about custom services here). In an inline JS code block you could do something like this:
<script type="application/javascript">
_stack.push(function(di) {
di.getService('snippetManager').on('after-update', function() {
// your code
});
});
</script>
Read more about what _stack
is here. Note that if this block is located in a snippet, it will be executed each time that snippet is redrawn - which in this case means that the event listener would get attached multiple times, which is probably not what you want.
Yes, this is it. Custom service solved my problem. Thank you. Btw custom download on nittro web returns error.
Hi, glad it worked, I'll look into the web builder issue asap..
Sign in to post a reply