gpt4 book ai didi

dart - 在Polymer中触发CustomEvent给我 “Exception: Class ' MyData'没有实例方法 '[]'”

转载 作者:行者123 更新时间:2023-12-03 03:46:49 24 4
gpt4 key购买 nike

class MyData {
String name;
String age;

MyData(this.name, this.age);
}

...
class AlertSimulatorElement extends PolymerElement {

void handleClick(e,d,t) {
asyncFire('polymer-signal',detail: new MyData("Mike",99));

// this works:
//asyncFire('polymer-signal', detail: {'name': "foo", 'data': "Foo!"});
}
}

asynFire给了我:

Exception: Class 'MyData' has no instance method '[]'.
NoSuchMethodError : method not found: '[]'
Receiver: Instance of 'MyData'
Arguments: ["name"]

我正在使用Chromium版本33.0.1750.48(251129)和聚合物0.9.5

Doc说我可以使用Object,但这似乎是错误的?有什么提示吗?
PolymerElement#fire: http://goo.gl/DYXMiZ
谢谢

最佳答案

Günter为我指明了正确的方向-这是* polymer_signals.dart中的错误*

polymer_signals.dart(第49行)

@initMethod
void registerListener() {
// signal listener at document
document.addEventListener('polymer-signal', (e) {
_notify(e.detail['name'], e.detail['data']);
});
}

作为目前的解决方法:

// (sender.dart)
asyncFire('polymer-signal',detail: { 'name' : "alertevent", 'data' : new MyData("Mike",47) });


// (receiver.html)
<polymer-element name="mm-alert-list" on-add-alert-event="{{handleAddAlert}}">
...
<polymer-signals on-polymer-signal-alertevent="{{fooSignal}}"></polymer-signals>
</polymer-element>

// (receiver.dart)
...
@CustomTag('mm-alert-list')
class AlertListElement extends PolymerElement {
...

fooSignal(final CustomEvent event, detail, sender){
print('<br>[my-app] got a [' + detail.name + '] signal<br>');
}

...
}

});

[ 更新]
提交了错误: https://github.com/ErikGrimes/polymer_elements/issues/143

关于dart - 在Polymer中触发CustomEvent给我 “Exception: Class ' MyData'没有实例方法 '[]'”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22962543/

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