问题
Definition:
<element name="x-card" constructor="Card" extends="div">
<template>
<div>{{titleText}}</div>
</template>
<script type="application/dart">
import 'package:web_ui/web_ui.dart';
class Card extends WebComponent {
String titleText = '';
}
</script>
</element>
Instantiation:
<x-card data-value="titleText:something"></x-card>
or
<x-card titleText="something"></x-card>
Nothing is working.
Here something
is not a variable. Its a string literal. How do i go about passing it?
Also what if i want to instantiate array of x-cards
? Say i have a dart array named cardTitleArray
.
回答1:
@financeCoding, data-value is deprecated. They say use attribute=value
instead of data-value="attribute:value"
.
Never mind, my problem is solved. The following works.
<x-card title-text="{{'Aint it supercool'}}"></x-card>
回答2:
Looking at the code that does make reference to 'data-value'
http://www.dartlang.org/articles/dart-web-components/#component-instantiation
https://github.com/dart-lang/web-ui/blob/master/example/explainer/countcomponent.html
It does not seem like the actual code uses it. Could you use the other way or now or post the code online? Maybe a space is needed after ':' ?
来源:https://stackoverflow.com/questions/13899000/how-to-pass-a-constant-or-literal-data-via-an-attribute-while-instantiating-dart