dialog callback

Today, I met a requirement that when submitting data, three confirmation menus need to pop up at the same time. After clicking the confirmation, the next pop-up box will appear, and the logic of the confirmation box after the pop-up is in each callback function after clicking the confirmation. There will be 3 nested relationships. Since it is the repetition of the same logic, it is natural to think of recursion to achieve it.



Confirmation of the popup:
  	mui.confirm(content.shift(), "", forupar, function(res) {

					if(res.index == 0){
//Click the confirmed callback function, and the second pop-up box will pop up at this time.
}


Here's an optimization:
You can do it using recursion:
var forupar = ["OK", "Cancel"];
		
		    var content=[
		    				"Is the description clear and the order address in the item description is clear?",
		    				"Is the photo correct?",
		    				"Is the item location accurate?("+$("#searchinput").val()+")"
		    			];
			function dialog(){
				mui.confirm(content.shift(), "", forupar, function(res) {
					if(res.index == 0){
						if(content.length==0){
							// perform the actual data submission operation
							add_report();
						}
						dialog();
return;
					}
				});

			}

			dialog();


That is, it keeps recursing itself to meet the needs.
Skill is stronger. It is better than writing the callback logic layer by layer directly. Because if there were 10 popups it would be Sabie.
It can also be done with the help of promises.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327057463&siteId=291194637