I have one route that I have to call inside loop from another controller, see for example.
for(var i=0;i<10;i++)
{
this.transitionToRoute("another_route");
}
I have tried this but not calling multiple times this route. Only when i=10 at that time this route is able transition.
Related
I'm reading the documentation at https://github.com/EventedMind/iron-router/blob/devel/Guide.md and I can't get a clear picture on when I would pass a function to the route() method and when I would pass an object.
Example for rendering a template with data -- passes a function as the second parameter:
Router.route('/post/:_id', function () {
this.render('Post', {
data: function () {
return Posts.findOne({_id: this.params._id});
}
});
});
Example for waiting for a subscription to complete -- passes an object as the second parameter:
Router.route('/post/:_id', {
// this template will be rendered until the subscriptions are ready
loadingTemplate: 'loading',
waitOn: function () {
// return one handle, a function, or an array
return Meteor.subscribe('post', this.params._id);
},
action: function () {
this.render('myTemplate');
}
});
As you can see, some examples in the documentation use one form and some use the other. Generally speaking, when I find some documentation that addresses what I have in mind, it uses a different form than the one I have adopted from following an example elsewhere in the documentation.
What is the relationship between the two forms? How do I mix and match?
I am currently learning of this myself. I have found that you can alternately do both methods as you mentioned, depending upon your needs.
The format is as you mentioned, that you can pass a function as the second argument for the route definition.
The biggest difference I have found is that using a function can override some settings in Router.config. It seems like for instance, you must be careful of how you define renderings, as to not override layout templates.
I feel like it's a matter of preference as I have seen many different examples of how to set up routes (for eg. Iron router and hooks).
Basically I am using Router.map() to try and handle most standard settings, and then looking to define hooks to control flow through the routers. Then I am looking to set up custom controllers as needed, and as the project scales out.
All in all, I feel myself drawn away from using a function in defining a route, since it requires more explicitness, although I can see it having a purpose, when wanting to more finely process routes, conditions, and parameters.
I'm developing a site (D6) that runs geocode lookups every time a node is inserted or updated, the node has an address textfield and hidden fields for a lat/lng pair, and during hook_nodeapi I want to call this geocoding function.
The issue is that the geocoder needs to save this new latlng pair to the node, which in turn calls hook_nodeapi, and thus my recursion issue has been spawned.
Whats the best method for avoiding this headache?
If you are completly sure, that you cannot change geocoder behavior, you can use simple workaround:
static $geocoded_nodes = array();
if (!$geocoded_nodes[$node->nid]) {
$geocoded_nodes[$node->nid] = TRUE;
call_geocoder_stuff().
}
As alternative, You can also can try to add non used field to node passed to geocoder logic.
if (!isset($node->geocoding_done)) {
$node->geocoding_done = TRUE;
call_geocoder_stuff($node).
}
I'm not sure if this field won't be discarded on node_save logic, but this should work.
I am using Flex and Actionscript 3, along with Webservices, rpc and a callResponder. I want to be able to, for example, say:
loadData1(); // Loads webservice data 1
loadData2(); // Loads webservice data 2
loadData3(); // Loads webservice data 3
However, Actionscript 3 works with async events, so for every call you need to wait for the ResultEvent to trigger when it is done. So, I might want to do the next request every time an event is done. However, I am afraid that threading issues might arise, and some events might not happen at all. I don't think I'm doing a good job of explaining, so I will try to show some code:
private var service:Service1;
var cp:CallResponder = new CallResponder();
public function Webservice()
{
cp.addEventListener(ResultEvent.RESULT, webcalldone);
service = new Service1();
}
public function doWebserviceCall()
{
// Check if already doing call, otherwise do this:
cp.token = service.WebserviceTest_1("test");
}
protected function webcalldone(event:ResultEvent):void
{
// Get the result
var result:String = cp.lastResult as String;
// Check if other calls need to be done, do those
}
Now, I could ofcourse save the actions in an arraylist, but whose to say that the addToArrayList and the check if other calls are available do not mess eachother up, or just miss each other, thereby halting execution? Is there something like a volatile Arraylist? Or is there a completely different, but better solution for this problem?
Use an AsyncToken to keep track of which call the returned data was for http://flexdiary.blogspot.com/2008/11/more-thoughts-on-remoting.html
When I want to store data in an async manor I put it in an array and make a function that will "pop" the element as I send it off.
This function will be called on complete and on error events.
Yes I know there could be an issue with the server and data lost but oh well. That can also be handled
Events will always fire however, it may not be a complete event that gets fired but could be an error event.
Once the array is empty the function is done.
I tried to call a service using a for loop and it seems that only the first service call seems to work. My guess is that once a service is called it needs to wait until result event until it can be called again. How can I workaround this?
Waiting for each service to complete before querying for another is too slow.
Ex.
callresponder id="test"
SomeService properly imported through Flash Builder 4
for (var i:int=0;i< pool.length;i++)
{
test.token = SomeService.getSomething(pool[i].someValue);
}
Only one would be successful. Help! I don't want to call after result event!
Problem: The problem is one call responder cannot be used by multiple service call.
Solution: Make more call responders....
var c:CallResponder;
before each iteration begins
c = new CallResponder();
c.addEventListener(ResultEvent.RESULT, resultHandler);
c.token = SomeService.whatEver(something);
I have implemented AJAX for calling server side function using client side function call i.e Calling server side function using javascript tag by using PageMethod in javascript.
I have few question regarding the same implementation.
function OnBlurCall()
{
chk(ControlId, SpanMsgId, FunctionName)// where all these parameters are obtained from programmer.
}
function chk(ControlId,SpanMsgId, FunctionName)
{
PageMethods.FunctionName(ControlId.value,onSuccess,onFail,SpanMsgId); // I want to replace actual value of FunctionName i.e Something given below
PageMethods.CheckUserNameAvailability(ControlId.value,onSuccess,onFail,SpanMsgId);
}
function onSuccess(result,MsgId,methodname)
{
MsgId.innerHTML=result;
}
function onFail(error,MsgId,methodname)
{
MsgId.innerHTML=error;
}
Ques 1. How many parameters can i add to this function. Is it there some limit that i can send only 3 parameters. Please give some details how it is working.
Ques 2. I want to make above code reusabe in javascript such that I add all the 3 functions in master page. But the problem is that i can add two functions into javascript at this time. But for adding 3rd function i have to send function name also as a parameter.
PageMethods.FunctionName(ControlId.value,onSuccess,onFail,SpanMsgId);
This FunctionName will be the name of server side function that a developer want to call.
Can i do this. ?
You can generically check for arguments; while in the function method, the arguments array has a list of all the arguments for that method. Check this out: https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Functions_and_function_scope/Arguments
To invoke dynamically, you could consider using the WebServiceProxy: http://www.asp.net/ajax/documentation/live/clientreference/Sys.Net/WebServiceProxyClass/WebServiceProxyInvokeMethod.aspx