3

我已经在聚合物 0.5 中构建了我的应用程序。

现在我已将其更新为聚合物 1.0。

对于响应式布局,我使用了 Polymer 0.5 中使用布局属性的自定义逻辑的布局属性。

请看下面的代码:

<template is="auto-binding">
<core-media-query query="max-width: 767px" queryMatches="{{smallScreen}}"></core-media-query>
<section layout vertical?="{{smallScreen}}" horizontal?="{{!smallScreen}}">
    <section flex four?="{{!smallScreen}}" auto?="{{smallScreen}}">
        <paper-input-decorator label="First name" floatingLabel>
            <input type="text" is="paper-input" id="fname" name="fname">
        </paper-input-decorator>
    </section>
    <section flex four?="{{!smallScreen}}" auto?="{{smallScreen}}">
        <paper-input-decorator label="Last name" floatingLabel>
            <input type="text" is="paper-input" id="lname" name="lname">
        </paper-input-decorator>
    </section>
</section>
</template>

现在在聚合物 1.0 中引入了一个元素“iron-layout-flex”,所有迹象都表明,现在我们必须使用“.layout”、“.horizo​​ntal”、“.vertical”类而不是属性?我应该如何根据布局属性的逻辑进行调整,这非常令人困惑。

所以,我的问题是,有没有办法使用“布局”作为属性而不是 CSS 类或在类属性中使用属性序列化?

4

2 回答 2

2

好吧,理论上您可以将属性转换为新的布局 css 属性。像这样的东西(未经测试,所以不能保证这会真正起作用)

<style is="custom-style">
  html /deep/ [layout][vertical] {
    @apply(--layout-vertical);
  }

  html /deep/ [layout][horizontal] {
    @apply(--layout-horizontal);
  }

  html /deep/ [flex][four] {
    @apply(--layout-flex-4);
  }

  html /deep/ [flex][auto] {
    @apply(--layout-flex-auto);
  }
</style>
于 2015-06-05T11:50:54.550 回答
1

从 Polymer 1.2 开始,现在可以使用compound binding查看Polymer 博客

这意味着,您现在应该能够执行以下操作:

<div class="someOtherClass [[addClassIf('horizontal', smallScreen)]] [[addClassIf('vertical', !smallScreen)]]" >
</div>

..
smallScreen: {
   type: Boolean,
   value: false,
}
..

addClassIf: function(classToAdd, shouldAdd)
{
   if(shouldAdd)
      return classToAdd;
}

现在可能有其他(更好的)方法可以做到这一点compound binding 。但这显示了如何做到这一点的概念。

于 2015-12-04T12:11:19.963 回答