gpt4 book ai didi

dart - polymer Dart 核心样式引用未解决

转载 作者:行者123 更新时间:2023-12-03 04:06:11 25 4
gpt4 key购买 nike

当我将参数传递给 Polymer 元素时,核心样式的 ref 没有得到解决。

这是子代码:

<link rel="import" href="packages/polymer/polymer.html">
<link rel="import" href="packages/core_elements/core_style.html">

<core-style id="s1" unresolved> div { background: yellow; } </core-style>
<core-style id="s2" unresolved> div { background: pink; } </core-style>

<polymer-element name='test-cell' attributes='s t' noscript>
<template>
<core-style ref="{{s}}"></core-style>
<div>{{t}}</div>
</template>
</polymer-element>

如您所见,有两种核心样式。

这是父代码。它需要一个 List 并用文本和样式引用实例化“test-cell”。
<polymer-element name='test-rows'>
<template>
<template repeat='{{ v in x }}'>
<test-cell s={{v.s}} t={{v.t}}></test-cell>
</template>
</template>
</polymer-element>

在这个简单的例子中,Dart 代码是内联的。这里是:
  <script type='application/dart'>
import 'package:polymer/polymer.dart';

//======================================
class Info {
String s, t;
Info(this.s, this.t) {}
}
//======================================
@CustomTag('test-rows')
class TestRows extends PolymerElement {

@observable List<Info> x = toObservable([]);

//-----------------------------------
TestRows.created() : super.created() {
x.add(toObservable(new Info('s1', 'first' )));
x.add(toObservable(new Info('s2', 'second')));
}
}
</script>

在生成的 HTML 中,文本通过 OK,但核心样式实例都有
ref="{{s}}"

并且不应用样式。我可以通过一些替代注释强制解析样式引用参数吗?它本质上是一个final/const。

最佳答案

更新

我认为问题是你的noscript在您的 test-cell元素。
据我所知,在没有支持脚本( noscript )的情况下,绑定(bind)在 Dart 中不起作用。

我认为在你的情况下 <test-cell>元素需要一个字段

@observable
var s;

使这项工作。

原来的

如果您曾经为 s 赋值,您的代码不会显示.

我怀疑 toObservable适用于普通 Dart 对象。据我所知,这是针对列表和 map 的。
Info类应该是这样的,你不需要使用 toObservable()用它。

  class Info extends Object with Observable {
@observable
String s;

@observable
String t;

Info(this.s, this.t) {}
}

关于dart - polymer Dart 核心样式引用未解决,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27032019/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com