![](/img/trans.png)
[英]AngularDart custom filter call() method required to be idempotent?
[英]AngularDart Filter call method throws error when 'items' is null
当我使用“过滤器”加载组件时,将在设置“项目”参数之前运行“调用”方法。 因此,我从第200行开始重复出现错误。最终,发送了“ items”,并且“ call”方法运行无误。
The null object does not have a method 'where'.
NoSuchMethodError: method not found: 'where'
Receiver: null
Arguments: [Closure: (dynamic) => dynamic]
STACKTRACE:
#0 Object._noSuchMethod (dart:core-patch/object_patch.dart:42)
#1 Object.noSuchMethod (dart:core-patch/object_patch.dart:45)
#2 Filter.call (package:angular/formatter/filter.dart:200:26)
这是我第一次使用AngularDart实现过滤器,并且这在我尝试过的两个组件中都在发生。 我的模板没有什么特别的:
<tr ng-repeat="appSession in appSessions | orderBy: orderByList | filter: filterObject">
appSessions列表是由属性设置的,或者如果未提供,则在attach方法中设置。 在这种情况下,它是由属性设置的。
@NgOneWay("app-sessions") List<AppSessionModel> appSessions;
@NgOneWay("mobile-user-id") int mobileUserID;
void attach() {
if (appSessions == null) {
if (mobileUserID != null) {
appSessionManager.getForUser(mobileUserID).then((sessions) {
appSessions = sessions;
});
} else if (!fromUserTable) {
appSessionManager.getOpen().then((sessions) {
appSessions = sessions;
});
}
}
}
其他人有没有经历过? 这里有计时错误吗?
谢谢山姆
经过更多的调试后,我确认我的列表在'attach'方法中永远不会为空,并且我确认Filter.call在'attach'方法之后运行。 事实证明,该问题与模板中的“ orderBy”有关。
我有这个:
<tr ng-repeat="appSession in appSessions | orderBy: orderByList | filter: filterObject">
如果我切换“ orderBy”和“ filter”,则不再有Filter.call错误:
<tr ng-repeat="appSession in appSessions | filter: filterObject | orderBy: orderByList">
我调试了OrderBy.call,但是它没有将'items'返回为null,因此问题似乎出在OrderBy和Filter之间,但是我对AngularDart的了解不足,以至于不知道那是什么。
您可以使用一个空列表初始化该字段
List<AppSessionModel> appSessions = [];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.