我有一個主GLTkComponent ============= xgltk.dart GLTkComponent。飛鏢==================================Dart綁定JsonObject錯誤:類型'List <dynamic>'不是'value'類型'JsonObject'的子類型
@observable
class GLTkComponent extends WebComponent {
ObservableList<JsonObject> ListTk = toObservable(new ObservableList<JsonObject>());
JsonObject currentRow;
cm.ViewType currentView;
inserted() {
populateAccountsTable();
currentView = cm.ViewType.LIST;
}
populateAccountsTable() {
ServiceStack.get("http://localhost:9998/dmtk").done((results) {
JSON.parse(results).forEach((data) {
JsonObject currentRow = new JsonObject.fromMap(data);
ListTk.add(currentRow);
});
}).fail((e)=>print("Error in xgltk.populateAccountsTable() ${e}")).go();
}
}
======== ===== xgltk.html ========================================== =
...
<body>
<element name="x-gltk" constructor="GLTkComponent" extends="div">
<template>
<div class="container-fluid"> <!--list -->
<div class="row-fluid">
<template instantiate="if currentView == cm.ViewType.LIST">
<x-gltk-list bind-list="ListTk" bind-current="currentRow" bind-view="currentView"></x-gltk-list>
</template>
</div>
</div> <!-- end div list -->
</template>
<script type="application/dart" src="xgltk.dart"></script>
</element>
</body>
...
============ xgltk-list.dart GlTkListComponent ======================== ==
@observable
class GlTkListComponent extends WebComponent {
ObservableList<JsonObject> list;
JsonObject current;
cm.ViewType view;
inserted() {
}
String handleMenuClickClass(){
if(current != null) {
return "";
}
else {
return "disabled";
}
}
handleRowClick(JsonObject row) {
current = list.firstWhere((e) => e.Tk == row.Tk);
assert(list is ObservableList<JsonObject>);
assert(current is JsonObject);
}
String handleRowClickClass(JsonObject row){
if(current != null) {
return row.Tk == current.Tk ? "info" :"";
}
else {
return "";
}
}
AddNew() {
}
}
======================= xgltk-list.html ================= ==========
---
<body>
<element name="x-gltk-list" constructor="GlTkListComponent" extends="div">
<template>
<div id="id_list"> <!--div list -->
<div class="span8" id="content">
<table class="table table-hover" id="id_list_table">
<thead>
<tr>
<th>Tài khoản</th>
<th>Tên tài khoản</th>
<th>Ngoại tệ</th>
<th>Định khoản</th>
<th>Công nợ</th>
<th>Sổ cái</th>
<th>Tk Mẹ</th>
</tr>
</thead>
<tbody template iterate="row in list">
<tr on-click="handleRowClick(row)" class="{{handleRowClickClass(row)}}">
<td>{{row["Tk"]}}</td>
<td>{{row["Ten_Tk"]}}</td>
<td>{{row["Ma_Nt"]}}</td>
<td><template instantiate="if row['Loai_Tk']"><i class="icon-check"></i></template></td>
<td><template instantiate="if row['Tk_Cn']"><i class="icon-check"></i></template></td>
<td><template instantiate="if row['Tk_Sc']"><i class="icon-check"></i></template></td>
<td><template instantiate="if row['Tk'] != row['Tk_Me']">{{row["Tk_Me"]}}</template></td>
</tr>
</tbody>
</table>
</div>
</div> <!-- div list -->
</template>
<script type="application/dart" src="xgltk-list.dart"></script>
<!-- for this next line to work, your pubspec.yaml file must have a dependency on 'browser' -->
<script src="packages/browser/dart.js"></script>
</element>
</body>
---
當我名單上點擊它的主要錯誤:
web_ui.observe: unhandled error calling Closure: (dynamic, dynamic) => dynamic from <observer 56>.
error:
type 'List<dynamic>' is not a subtype of type 'JsonObject' of 'value'.
stack trace:
#0 GLTkComponent.currentRow= (http://127.0.0.1:3030/Z:/future13/3SNext/web/out/xgltk.dart:126:29)
#1 GLTkComponent.created_autogenerated.<anonymous closure>.<anonymous closure> (http://127.0.0.1:3030/Z:/future13/3SNext/web/out/xgltk.dart:62:56)
#2 DomPropertyBinding._safeSetter (package:web_ui/templating.dart:360:11)
#3 DomPropertyBinding.insert.<anonymous closure> (package:web_ui/templating.dart:369:58)
#4 _ExpressionObserver._runCallback (package:web_ui/observe/observable.dart:556:16)
#5 _ExpressionObserver._deliver (package:web_ui/observe/observable.dart:640:17)
#6 deliverChangesSync.deliverChangesSync.<anonymous closure> (package:web_ui/observe/observable.dart:435:58)
#7 SplayTreeMap.forEach (dart:collection/splay_tree.dart:209:8)
#8 deliverChangesSync.deliverChangesSync (package:web_ui/observe/observable.dart:435:33)
#9 setImmediate.<anonymous closure> (package:web_ui/src/utils_observe.dart:29:13)
#10 _ReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:81:92)
如何解決此問題。請幫幫我。 非常感謝。
疃晃映
嗨 - 這裏的JSONObject作者。你可以分享一個JSON文本的例子,你傳遞給'JSON.parse(results).forEach((data){' –
'這裏是:[{「Tk」:「111」,「Ten_Tk」:「 Tiềnmặt「...},.......... {」Tk「:」911「,」Ten_Tk「:」Xácđịnhkếtquảkinh doanh「...}] –
xgltk-list.html可以顯示,但是當綁定值GlTkListComponent.current返回到GLTkComponent.currentRow時發生錯誤。也許@observable不能支持JsonObject。 –