Originally in a bit confused situation, may be that period of time to write JS write dizzy, almost put him is the customer service side code to forget. The teacher's word mvc is as good as bluntness, wake me up from a dream, say no more, first give the slag code before
//Calculate Total Price var cnt= 0; $ (". Price"). each (function () { cnt + =parseint (This). text ()); }); $ ("#count "). Text (CNT); //Create array var a=new array (); var i=0; $ (". MenuId"). each (function () { a[i]=$ (this). attr ("Sid"); i++; }); // Statistics Code b = new array (); for (Var index in a) { if (B[a[index]] == null) b[a[index]] = 1; else b[a[index]]++; } // Output Statistics for (VAR INDEX IN B) { console.info (index ); $ ("." +index). Slice (1). Remove (); $ (". Copy_" +index). Text (B[index]); }
Do not pay attention to see, these code is one of my lessons, this in the case of DOM is generated by the DOM processing is obviously very unwise, can not be said to negate, but there is a better solution (and just relative)
Processing data in the backend only needs to be as simple as:
map<restaurantmenu,integer> Restaurantmenumap = new linkedhashmap<restaurantmenu,integer> (); for (Orderinguser orderinguser:orderingusers) {Integer count= restaurantmenumap.get (orderinguser.getrestaurantme Nu ()); Restaurantmenumap.put (Orderinguser.getrestaurantmenu (), (count = = null)? 1:count + 1); Countprice+=orderinguser.getrestaurantmenu (). GetPrice (); }
Restaurantmenumap is the result you want to get. Coutprice is the sum of calculations.
Eat a pad your wit, key value can be stored object, I am not the first day to know, but it is the first time to use. How do you feel about the students after reading them? Welcome to share your criticism!
To calculate the number of repetitions by map