首页 \ 问答 \ Angular有像extjs这样的flex布局吗?(Does Angular have a flex layout like extjs?)

Angular有像extjs这样的flex布局吗?(Does Angular have a flex layout like extjs?)

ExtJS有一个非常有用的布局机制,叫做flex。 它的工作原理是对行或列中的所有内容求和。 然后使用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: flexdisplay: 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:

Flex layout

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 or display: 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
更新时间:2022-03-15 11:03

最满意答案

对此的解决方案不是使用“类似”反射,而是实际使用反射。 无论如何,任何库或框架都很可能基于反射。

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标签的选择实际上取决于字段的内容。 一般来说,如果只打印字段名称,则字段列表听起来合理。 如果打印名称和值,则可以使用定义列表dltable


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 a getFields() method in Item 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 a table.

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)