我有一个团队名单在我的组成部分。这些团队列在组件的html-模板中。我创建了add和update函数,它们正在工作,但是如果我试图访问team的一个成员变量,我会得到一个错误: NoSuchMethodError: undefined不是一个函数:
void delete(int id, String name, int onlineId){
Team tempTeam;
html.window.console.info("In delete()");
for(int i = 0; i < teamList.length; i++){
if(teamList.elementAt(i).id == selectedTeam){ // <-- this fails
tempTeam = teamList.elementAt(i);
}
}
...
html.window.console.info("Deleting team: " + name + " succeded!");
}以下是组件:
@Component(
selector: 'admin-teams-view',
templateUrl: 'packages/fremad/components/admin/teams_view.html',
cssUrl: 'packages/fremad/components/admin/teams_view.css',
useShadowDom: false
)
class ShowAdminTeamsComponent {
List<Team> teamList;
int selectedTeam = -1;
bool isEditing = false;
...
}这里是值得关注的html。
<li ng-repeat="team in teamList">
<div class="item-name" ng-click="selectTeam(team.id)">
{{team.name}}
</div>
<div class="item-edit" ng-hide="isActive(team.id)">
<form>
Name:
<input type="text" size="35" ng-model="team.name">
Online ID:
<input type="number" size="15" ng-model="team.onlineId">
<input type="button" class="adminButton redButton" value="delete" ng-click="delete(team.id, team.name, team.onlineId)">
</form>
</div>
</li>我会感谢你的帮助!
从控制台执行打印(TeamListi)和打印(teamListi.name)后:
{id: 1, name: Fremad Famagusta Menn Senior A, onlineId: 30296} js_primitives.dart:25
NoSuchMethodError: undefined is not a function
STACKTRACE:
TypeError: undefined is not a function
at dart.J.get$name$x (http://localhost:8080/fremad/fremad_main.dart.js:40910:39)
at ShowAdminTeamsComponent.delete$3 (http://localhost:8080/fremad/fremad_main.dart.js:34640:22)
at eval (eval at <anonymous> (http://localhost:8080/fremad/fremad_main.dart.js:2922:12), <anonymous>:2:42)
at dart.Primitives_applyFunction (http://localhost:8080/fremad/fremad_main.dart.js:2609:23)
at StaticClosureMap_lookupFunction_closure.call$3 (http://localhost:8080/fremad/fremad_main.dart.js:11389:18)
at ClosureMapLocalsAware_lookupFunction_closure.call$3 (http://localhost:8080/fremad/fremad_main.dart.js:9546:79)
at CallScope.methodClosure$3 (http://localhost:8080/fremad/fremad_main.dart.js:9851:33)
at CallScope.eval$2 (http://localhost:8080/fremad/fremad_main.dart.js:9868:19)
at _UnwrapExceptionDecorator.eval$2 (http://localhost:8080/fremad/fremad_main.dart.js:9359:31)
at _UnwrapExceptionDecorator.eval$2 [as eval$1] (http://localhost:8080/fremad/fremad_main.dart.js:9372:19) 编辑:我的TeamList就是这样加载的:
void loadData() {
tableLoaded = false;
_http.get('rest/team/getTeams.json')
.then((HttpResponse response) {
teamListObject = new TeamList.fromJson(response.data);
teamList = teamListObject.teamList;
tableLoaded = true;
html.window.console.info("Success on loading table");
})
.catchError((e) {
print(e);
tableLoaded = false;
});
} 这是一堂课:
class TeamList {
bool empty;
List<Team> teamList;
TeamList(this.empty, this.teamList);
Map<String, dynamic> toJson() => <String, dynamic>{
"emtpy" : empty,
"listObject": teamList
};
TeamList.fromJson(Map<String, dynamic> json) : this(
json['empty'], json['listObject']);
}发布于 2014-10-29 11:46:16
您需要在fromJson类中更改TeamList:
TeamList.fromJson(Map<String, dynamic> json) : this(
json['empty'], new List<Team>.from(json['listObject'].map((x) => new Team.fromJson(x))));Dart不以这种方式理解嵌套类。您已经尝试以地图的形式访问映射listObject,而不是列表。
https://stackoverflow.com/questions/26512332
复制相似问题