多个循环-成本太高吗? [英] Multiple Loops - Is it too costly?

查看:41
本文介绍了多个循环-成本太高吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这会有点冗长:(请仔细阅读到底.

我有一个页面来添加产品.用户添加产品时,要求他/她添加规格.我具有特定类别的所有属性,例如手机",例如Camera,OS,Type等.所有属性都分为几组(请参见下表).如果用户正在上载手机"类别中的产品,我想选择类别中的所有组,然后选择组中的属性,并将其显示在UI上.请通过步骤了解情况.

表(类别组)

http://i.stack.imgur.com/D20o3.png [
表(GroupAttributes):

http://i.stack.imgur.com/qNHFW.png [
第3步:对于每行,检查`canSelectMultiple`是`True`还是`False`.

第4步:如果canSelectMultiple是False,则将DropDownList添加到页面中,并将Value列中的每个值添加到DropDownList中.[** Value列具有半冒号分隔的值* *]即在第一行中添加`DropDownList`,其值为"Android","Bada","Blackberry",Symbian,"iOS"

如果"canSelectMultiple"为"True",则将"CheckBoxes"添加到页面,并为值"列中的每个值添加一个"CheckBox".

第5步:将用户选择的值保存在DB上的Button Click上.


这就是我打算做到的方式(使用循环,即FOR NEXT).还有其他方法吗?我可以使用jQuery/Javascript在客户端执行此操作吗?我个人不想使用这么多循环,因为这会太昂贵.

This is going to be a bit lengthy:( Kindly read it to the end.

I have a page to add products. When the user adds product, he/she is asked to add the specifications . I have all the attributes for a particular category say `Mobiles` like Camera,OS,Type etc etc. All the attributes are divided into groups(See Table Below). If the user is uploading a product in `Mobiles` category , I want to select all the groups ith the category and then the attributes in the Group and display it on the UI. Kindly go through the steps to understand the scenario.

Table (CategoryGroups)

http://i.stack.imgur.com/D20o3.png[^]


Step 1 : Select all the groups from a particular `NodeID`

Table (GroupAttributes) :

http://i.stack.imgur.com/qNHFW.png[^]

Step 2 : Display all the Attributes to the user Grouped By `GroupName` i.e `AttributeID` 1 & 2 should come under `Group 1` , `AttributeID` 3 & 4 should come under `Group 2`

Step 3 : For each row check if `canSelectMultiple` is `True` or `False` .

Step 4 : If `canSelectMultiple` is `False` Add `DropDownList` to the page and add each Value in `Value` column to the `DropDownList`[**Value column has semi colon separated values**] i.e for the 1st row Add `DropDownList` with Values "Android","Bada","Blackberry",Symbian,"iOS"

ElseIf `canSelectMultiple` is `True` the Add `CheckBoxes` to the page with one `CheckBox` for every value in `Value` Column.

Step 5 : Save the values selected by the user in DB on Button Click.


This is the way i intend to do it (using loops i.e FOR NEXT). Any other way to do it?? Can i do it in client end using `jQuery/Javascript`. I personally do not want to use these many loops because it would be too costly. Any help appretiated.

推荐答案

循环实际上是编程中的基本工具.您无法避免.您为什么认为它们昂贵"?实际上,您可以使代码消耗太多的资源,但这不仅仅因为您使用了循环.您能想象例如在jquery中或在asp.net本身的代码中有多少个循环吗?
Loops are really basic tools in programming. You can not avoid them. Why do you think they are "costly"? Actually you can make a code consume too many resources, but that would not be just because you use loops. Can you imagine how many loops are in jquery for example, or in the code of asp.net itself?


不是循环数衡量了性能成本,而是许多其他因素,而且通常会使那些多个循环"的关注变得微不足道.

这是您首先需要了解的内容:
http://en.wikipedia.org/wiki/Computational_complexity_theory [ http://en.wikipedia.org/wiki/Time_complexity [ http://en.wikipedia.org/wiki/Big_O_notation [ http://en.wikipedia.org/wiki/Small_o_notation#Related_asymptotic_notations [
Not the number of loops measures the cost for the performance, but many other factors, and they usually make those "multiple loops" concerns nearly insignificant.

This is something you need to understand first:
http://en.wikipedia.org/wiki/Computational_complexity_theory[^],
http://en.wikipedia.org/wiki/Time_complexity[^].

Now, the measurement and notation. Even though the notation does not have the fundamental role compared to the role of the theory itself, you won''t be able to understand many statements and issues if you don''t understand the notation. This is the one which is nearly always referred to:
http://en.wikipedia.org/wiki/Big_O_notation[^].

It''s also good to understand a number of similar or related notations mentioned in the same article:
http://en.wikipedia.org/wiki/Small_o_notation#Related_asymptotic_notations[^]

Good luck,
—SA


这篇关于多个循环-成本太高吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆