【问题标题】:Polymer core-selector does not refresh聚合物核心选择器不刷新
【发布时间】:2014-09-24 12:51:19
【问题描述】:

我的 Polymer 元素的 Dart 代码如下所示:

@CustomTag('my-element')
class MyElement extends PolymerElement {
  final List<String> colors = toObservable(['red', 'green', 'blue']);
  MyElement.created() : super.created();
}

HTML 看起来像这样:

<polymer-element name="my-element">
  <template>
    <style>
      .core-selected {
        font-weight: bold;
      }
    </style>
    <core-selector id="selector" selected="1">
      <template repeat="{{color in colors}}">
        <div value="{{color}}">{{color}}</div>
      </template>
    </core-selector>
    <hr>
    <!-- Prints the selected index, but does not update -->
    <div>{{$['selector'].selected]}}</div> 
  </template>
  <script type="application/dart" src="my_element.dart"></script>
</polymer-element>

使用&lt;div&gt;{{$['selector'].selected]}}&lt;/div&gt; 可以正确显示所选color 的索引,但选择不同的颜色不会刷新selected 的值。我正确使用它吗?或者这是一个错误?

【问题讨论】:

  • 我希望这能奏效。 selected 是一个已发布的属性,因此应该是可观察的。也许是 Dart 包装器的问题。
  • 君特,我相信你是对的。我提交了一个错误:github.com/dart-lang/core-elements/issues/115.
  • 你打错了:{{$['selector'].selected]}} 应该是 {{$['selector'].selected}}

标签: dart dart-polymer


【解决方案1】:

我同意这是一个错误,但与此同时,您可以像这样解决它

<core-selector id="selector" selected="{{selected}}">
...
<div>{{selected}}</div>

带有明显的支持代码

@observable int selected = 1;

我想知道您的版本在纯 JS 环境中使用时是否有效?但这是另一个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多