Dart Polymer 错误 'List' 不是 'value' 类型 'ObservableList' 的子类型
Dart Polymer error 'List' is not a subtype of type 'ObservableList' of 'value'
我正在使用 core-ajax-dart 获取一些数据并将其放入 core-list-dart。而且我不断收到此错误。我能够成功传递字符串标题,但无法传递联系人。它因以下错误而失败
Exception: Uncaught Error: type 'List' is not a subtype of type
'ObservableList' of 'value'.
主页
<core-ajax-dart auto id="_ajax" url="https://polymer-contacts.firebaseio.com/{{category}}.json" handleAs="json"></core-ajax-dart>
<contacts-page class="page" id="contacts" contacts="{{contacts}}" heading="{{heading}}" flex></contacts-page>
List contacts;
ContactsPage cp = $['contacts'] as ContactsPage;
var ajax = $['_ajax'] as CoreAjax;
ajax.on["core-response"].listen((event) {
var detail = event.detail;
var response = detail['response'];
cp.contacts = response;
});
元素定义
<div id="title" flex>{{heading}}</div>
<core-list-dart id="list" data="{{contacts}}">
@published List contacts;
@published String heading;
堆栈跟踪:
Exception: Uncaught Error: type 'List' is not a subtype of type 'ObservableList' of 'value'.
Stack Trace:
#0 CoreList.data= (package:core_elements/core_list_dart.dart:48:124)
#1 main.<anonymous closure> (http://localhost:8080/index.html_bootstrap.dart:114:27)
#2 GeneratedObjectAccessorService.write (package:smoke/static.dart:114:11)
#3 write (package:smoke/smoke.dart:34:40)
#4 _updateNode (package:polymer/src/instance.dart:1412:16)
#5 _convertAndCheck (package:polymer_expressions/polymer_expressions.dart:302:16)
#6 _RootZone.runUnaryGuarded (dart:async/zone.dart:1093)
#7 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341)
#8 _DelayedData.perform (dart:async/stream_impl.dart:595)
#9 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:711)
#10 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:671)
#11 _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:41)
#12 _asyncRunCallback (dart:async/schedule_microtask.dart:48)
#13 _handleMutation (dart:html:41817)
<core-list-dart>
的数据属性需要 ObservableList
而不是 List
。
您可以将字段更改为 getter/setter,其中传递的 List
会自动转换为 ObservableList
,如
class Model extends Object with Observable {
// or class SomeElement extends PolymerElement {
ObservableList _contacts;
@observable ObservableList get contacts => _contacts;
set contacts(List contacts) {
final old = _contacts;
if(contacts is ObservableList) {
_contacts = contacts;
}
_contacts = toObservable(contacts);
notifyPropertyChange(#contacts, old, _contacts);
}
}
我正在使用 core-ajax-dart 获取一些数据并将其放入 core-list-dart。而且我不断收到此错误。我能够成功传递字符串标题,但无法传递联系人。它因以下错误而失败
Exception: Uncaught Error: type 'List' is not a subtype of type 'ObservableList' of 'value'.
主页
<core-ajax-dart auto id="_ajax" url="https://polymer-contacts.firebaseio.com/{{category}}.json" handleAs="json"></core-ajax-dart>
<contacts-page class="page" id="contacts" contacts="{{contacts}}" heading="{{heading}}" flex></contacts-page>
List contacts;
ContactsPage cp = $['contacts'] as ContactsPage;
var ajax = $['_ajax'] as CoreAjax;
ajax.on["core-response"].listen((event) {
var detail = event.detail;
var response = detail['response'];
cp.contacts = response;
});
元素定义
<div id="title" flex>{{heading}}</div>
<core-list-dart id="list" data="{{contacts}}">
@published List contacts;
@published String heading;
堆栈跟踪:
Exception: Uncaught Error: type 'List' is not a subtype of type 'ObservableList' of 'value'.
Stack Trace:
#0 CoreList.data= (package:core_elements/core_list_dart.dart:48:124)
#1 main.<anonymous closure> (http://localhost:8080/index.html_bootstrap.dart:114:27)
#2 GeneratedObjectAccessorService.write (package:smoke/static.dart:114:11)
#3 write (package:smoke/smoke.dart:34:40)
#4 _updateNode (package:polymer/src/instance.dart:1412:16)
#5 _convertAndCheck (package:polymer_expressions/polymer_expressions.dart:302:16)
#6 _RootZone.runUnaryGuarded (dart:async/zone.dart:1093)
#7 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341)
#8 _DelayedData.perform (dart:async/stream_impl.dart:595)
#9 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:711)
#10 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:671)
#11 _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:41)
#12 _asyncRunCallback (dart:async/schedule_microtask.dart:48)
#13 _handleMutation (dart:html:41817)
<core-list-dart>
的数据属性需要 ObservableList
而不是 List
。
您可以将字段更改为 getter/setter,其中传递的 List
会自动转换为 ObservableList
,如
class Model extends Object with Observable {
// or class SomeElement extends PolymerElement {
ObservableList _contacts;
@observable ObservableList get contacts => _contacts;
set contacts(List contacts) {
final old = _contacts;
if(contacts is ObservableList) {
_contacts = contacts;
}
_contacts = toObservable(contacts);
notifyPropertyChange(#contacts, old, _contacts);
}
}