如果我的React Native应用程序无法连接到其后端,我会显示一个带有OK按钮的警报.如果发生这种情况,应用程序继续运行没有任何意义,因此我想在单击按钮时将其关闭.我该怎么做呢?
我怀疑关键是在AppRegistry中,但文档有点不足.
我想实现一个设置,我可以在主模块中定义"根状态",然后在其他模块中添加子状态.这个,因为我需要根状态才能解决才能进入子状态.
显然,根据此FAQ,这应该是可能的: 如何:从多个模块配置ui-router
对我来说它不起作用: 错误未捕获错误:从ngBoilerplate.foo没有这样的状态'app'
这是我有的:
app.js
angular.module( 'ngBoilerplate', [
'templates-app',
'templates-common',
'ui.state',
'ui.route',
'ui.bootstrap',
'ngBoilerplate.library'
])
.config( function myAppConfig ( $stateProvider, $urlRouterProvider ) {
$stateProvider
.state('app', {
views:{
"main":{
controller:"AppCtrl"
}
},
resolve:{
Auth:function(Auth){
return new Auth();
}
}
});
$urlRouterProvider.when('/foo','/foo/tile');
$urlRouterProvider.otherwise( '/foo' );
})
.factory('Auth', ['$timeout','$q', function ($timeout,$q) {
return function () {
var deferred = $q.defer();
console.log('before resolve');
$timeout(function () {
console.log('at resolve');
deferred.resolve();
}, 2000);
return deferred.promise;
};
}])
.run(function run( $rootScope, $state, $stateParams ) …
Run Code Online (Sandbox Code Playgroud) 有没有办法可以"循环"Scala中指定包中的类集?
用例是管理从BaseService特征继承的一组服务,这些特性通过提供的名称暴露给REST API.Manager类需要能够提供服务列表以及验证所提供的服务是否存在,如果存在,则将其实例化为执行重载函数.
我的想法是这样的伪代码:
for ( clazz <- com.demo.pkg ) {
val service = Class.forName(clazz).newInstance
registerService( service )
}
Run Code Online (Sandbox Code Playgroud)
而不是实例化,同名对象上的静态方法提供服务名称和描述可能会更好.
在Python中,这是微不足道的,因为dir()并且由于类加载器函数在PHP中相当容易,但我是Scala的新手.
此外,我知道我可能正在接近这个错误,并欢迎反馈.
更新:
我接受了下面JPP的答案,但他说的是,这对于日常操作而言过于昂贵.所以我需要改变我的方法.而管理器类将维护一个静态的服务clases列表.虽然从开发角度来看并不理想,但运行时速度增益似乎非常值得.
试图理解AngularJS的"过滤器"功能,大多数示例都在视图/ HTML端有过滤器,但我需要在控制器/ JS端.
这有效
$scope.getPickedPeopleCount = function(){
var thisCount = 0;
angular.forEach($scope.allPeople, function(person){
if(person.PICKED){thisCount++}
});
return thisCount;
}
Run Code Online (Sandbox Code Playgroud)
但这失败了
$scope.getPickedPeopleCount = function(){
return $scope.allPeople.filter(PICKED:'true').length;
}
Run Code Online (Sandbox Code Playgroud)
显然我的语法错了,有人能指出我正确的方向