Angular有像extjs这样的flex布局吗?(Does Angular have a flex layout like extjs?)
ExtJS有一个非常有用的布局机制,叫做flex。 它的工作原理是对行或列中的所有内容求和。 然后使用flex值除以所有flex值的总和来分隔空间。 这导致如下布局:
红色框是一个hbox布局,块E和F具有总和为3的给定弹性值,因此E得到屏幕宽度的1/3,F得到2/3rds。
蓝色框是另一个hbox布局,其中所有4个部分(AD)具有相同的flex,因此每个部分获得25%的空间。
未显示的是周围的vbox布局,其中蓝色框的flex为22,红色框的flex为78。
Angular中有这种布局吗? 如果没有,你会怎么把它放在Angular中?
基于以下一些答案的其他信息:
我希望能够用Angular替换extjs。 要做到这一点,我需要一些我在extjs中有的功能,我不知道它存在于Angular中。 我已经找到了观察屏幕尺寸的方法,改变以调整整体显示尺寸,但是我还没有看到一个很好的例子,该指令基本上是对这个flex值的组成指令进行内省,并根据尺寸设置它们的大小改变容器的事件。 Flex不能在div内部工作,它在div的容器内工作,因为它必须遍历容器中的所有div才能正确划分空间。 我还没有看到过这样做的角度指令。
我没有Angular的实际开发经验(我已经看过很多来自http://egghead.io的视频,我已经阅读了文档和教程,听了这个播客: JSJ-Angular )所以我不知道知道这是否易于解决,或难以解决,或者有人已经解决了。 这种灵活的布局非常酷且易于使用,实际上对于整页应用程序,我不确定是否有更简单的方法来布局它们以便它们保持全屏并且具有可调整大小的屏幕尺寸。 网格系统对某些东西很有用,但它们没有解决弹性系统所处理的问题。
我试图看看是否有办法从extjs跳到Angular而不会让我的生活变得困难。
其他发现的信息:
看起来flex现在以CSS
display: flex
的形式成为显示类型display: flex
或display: inline-flex
(目前有前缀)https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Flexible_boxes
有趣的是看到插图称之为
Holy Grail Layout example
。 当然IE不会正确或及时地实现它,但我的客户不介意使用Chrome,如果它完成了工作。ExtJS has a very useful layout mechanism called flex. It works by summing all the things on a row or in a column. Then the space is parceled out using the flex value divided by the sum of all the flex values. This results in a layout like below:
The Red box is an hbox layout, the blocks E and F have the given flex values that sum up to 3, so E gets 1/3 the width of the screen, and F gets 2/3rds.
The Blue box is another hbox layout, where all 4 pieces (A-D) have the same flex so each one gets 25% of the space.
What isn't shown is the surrounding vbox layout where the blue box has a flex of 22 and the red box has a flex of 78.
Is there anything like this kind of layout in Angular? If there isn't, how would you put this together in Angular?
Additional information based on some of the answers below:
I want to be able to replace extjs with Angular. To do that I need some functionality that I have in extjs that I don't know exists in Angular. I've found ways to watch for screen size, change to adjust the overall display size, but I haven't seen a good example yet of a directive that essentially introspects its constituent directives for this flex value and sets their size based on a size change event of the container. Flex doesn't work from inside the divs, it works inside the container of the divs, because it has to go across all the divs in the container to divide the space correctly. I haven't seen an angular directive that does this yet.
I have no actual development experience with Angular yet (I've watched many of the videos from http://egghead.io, I've read documentation and tutorials, listened to this podcast: JSJ-Angular) and so I don't know if this is something that is easy to solve, or hard to solve, or if someone has already solved it. This flex layout is wickedly cool and easy to use, in fact for full page apps, I'm not sure there is an easier way to lay them out so that they stay full screen and are malleable to screen size changes. Grid systems are great for some things, but they don't address what the flex system addresses.
I'm trying to see if there is a way to leap from extjs to Angular without really making my life difficult.
Additional discovered information:
Looks like flex is becoming a display type now in the form of the CSS
display: flex
ordisplay: inline-flex
(with prefixes at the moment)https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Flexible_boxes
Interesting to see the illustration calls it the
Holy Grail Layout example
. Of course IE won't implement it right, or in a timely fashion, but my customers don't mind using Chrome if it gets the job done.
原文:https://stackoverflow.com/questions/18732240
最满意答案
对此的解决方案不是使用“类似”反射,而是实际使用反射。 无论如何,任何库或框架都很可能基于反射。
objects 类提供了声明声明或声明和继承字段所需的所有方法。 字段类包含有关实际字段的所有信息,例如其名称,类型或值。
例
要在页面上显示的某些类:
public class Item { public String foo = "bar"; public int x = 23; }
模板:
@(item: Item) <ul> @for(field <- item.getClass().getDeclaredFields()) { <li>@field.getName() = @field.get(item)</li> } </ul>
输出:
<ul> <li>foo = bar</li> <li>x = 23</li> </ul>
请记住,模板可能不是正确的地方,特别是如果您想要过滤字段或其他内容。 您应该将代码移动到控制器,甚至更好地移动到模型。 由于您知道对象是
Item
,因此您可以在Item
中创建一个getFields()
方法,您可以在其中实现更复杂的逻辑并返回字段或字段名称列表。
语义html标签的选择实际上取决于字段的内容。 一般来说,如果只打印字段名称,则字段列表听起来合理。 如果打印名称和值,则可以使用定义列表
dl
或table
。The solution to this is not using "something like" reflections but to actually use reflections. Any library or framework for this will be most likely based on reflections anyway.
The objects class provides all methods you need to get declared or both declared and inherited fields. The field class contains all information about the actual field, like its name, type or value.
Example
Some class to display on the page:
public class Item { public String foo = "bar"; public int x = 23; }
Template:
@(item: Item) <ul> @for(field <- item.getClass().getDeclaredFields()) { <li>@field.getName() = @field.get(item)</li> } </ul>
Output:
<ul> <li>foo = bar</li> <li>x = 23</li> </ul>
Keep in mind that the template might not be the right place to do this, especially if you maybe want to filter the fields or something. You should move the code to the controller, or even better to the model. Since you know the object is an
Item
, you could create agetFields()
method inItem
where you implement more complex logic and return a list of fields or field names.
The choice of semantic html tags really depends on the content of your fields. Generally speaking, if you only print the field name, a list of fields sounds reasonable. If you print names and values, you could use a definition list
dl
or maybe atable
.
相关问答
更多-
在令人不安的代码解决问题之前仅放置此行: @play.mvc.Http.Context.current.set(play.core.j.JavaHelpers.createJavaContext(request)) @forProviders(playAuth, skipCurrent) { p => 试图使它更清洁一点,即它不会一直重置,但对我来说这仍然是一个谜,为什么这不起作用: @if (play.mvc.Http.Context.current.get() == null) { @pla ...
-
您可以通过以下方式访问模板中的反向路线: @routes.controllersFolder.MyControllerName.endPointName 这将解决路线。 例如路线文件: GET /myApp/endpointExample controllersFolder.MyControllerName.endPointName 所以 @routes.controllersFolder.MyControllerName.endPointName 会解决: /myApp/endpointExa ...
-
是依赖Java依赖注入的Scala播放依赖注入框架吗? 是的,所以你需要编写使用DI的import javax.inject._ everyfile。 你需要做的基本上是 ·将接口定义为trait trait FooService { def getBar(baz: String):Future[Bar] } ·实现界面 class FooServiceImpl extends FooService { def getBar(baz: String) = ??? } ·通过Module.scal ...
-
Hibernate,Scala和Play(Hibernate, Scala and Play)[2023-06-08]
Lightbend网站上有一个模板可以满足您的需求。 它确实在Java中,但它很容易适应Scala。 您可以手动下载它或使用activator ui从激活器Web界面实例化模板。 您还可以使用activator new命令从CLI实例化一个。 你的问题太模糊了,无法得到“正确答案”。 There is a template from the Lightbend website that will fit your needs. It is indeed in Java but it is easy to a ... -
Play 2框架:scala在视图中迭代java对象的字段(Play 2 framework: scala iterate through fields of java objects in view)[2024-05-06]
对此的解决方案不是使用“类似”反射,而是实际使用反射。 无论如何,任何库或框架都很可能基于反射。 objects 类提供了声明声明或声明和继承字段所需的所有方法。 字段类包含有关实际字段的所有信息,例如其名称,类型或值。 例 要在页面上显示的某些类: public class Item { public String foo = "bar"; public int x = 23; } 模板: @(item: Item)-
@for(field <- item.getClass( ...
-
通过直接在HTML中显示日期来检查日期的呈现方式,例如@intake.daterequested 我怀疑它的格式为dow mon dd hh:mm:ss zzz yyyy (参见日期#toString的javadoc ),它与yyyy-mm-dd所需的格式不匹配。 您可以在模板中使用SimpleDateFormat来根据需要格式化日期,或者为已经包含所需格式的日期的Intake创建DTO。 如果选择前者,请将代码更改为具有以下内容: value="@(new SimpleDateF ...
-
要在Twirl的模板中定义方法,请在名称和代码块之前添加@ @incr(number: Int) = @{ @number + 1 } 要在名称前调用scala方法或变量add @ symbol@incr(10)将在div块中返回并打印11 To define a method inside Twirl's template add @ before the name and code block @incr(number: Int) = @{ @number + 1 } T ...
-
你需要知道scala来玩玩java框架吗?(do you need to know scala to play around with java play framework)[2022-12-17]
你可以在不知道太多Scala的情况下用Java写你的应用程序(除了视图)。 但是,当出现问题时,您将希望能够读取Scala来调试框架本身。 You can write your application in Java without knowing much Scala (except for the views). When things go wrong, though, you will want to be able to read Scala to debug the framework itse ... -
事实证明,类F.Promise(java.play)有一个名为wrapped()的方法,它返回由Promise包装的scala.concurrente.Future 。 所以你所要做的就是用F.Promise打包。 val promise: F.Promise[T] = getPromise() val future : Future[T] = promise.wrapped() It turns out that the class F.Promise (java.play) has a method ...
-
从这里找到答案: http : //d.hatena.ne.jp/k4200/20110807/1312737091 简答: Play 1.2.2与GAE有问题。 需要使用Play 1.2.1 + scala 0.9模块 Found the answer from here: http://d.hatena.ne.jp/k4200/20110807/1312737091 Short Answer: Play 1.2.2 has issues with GAE. Need to use Play 1.2.1 ...