我有一个jQuery onClick处理程序,用这样的匿名函数写:
$("#selector").on("click" function(){
// do something
})
Run Code Online (Sandbox Code Playgroud)
我会概括在命名函数中提取逻辑的匿名函数,它驱使我做类似的事情:
$("#selector").on("click" namedFunction())
function namedFunction(){
// do something
}
Run Code Online (Sandbox Code Playgroud)
对我来说似乎是个好方法.但是有一个缺点,因为在namedFunction脚本加载后执行.在这里你可以测试不良行为.
我是Ionic 2的新手和周围的一切.我正在尝试设置我的第一个移动应用程序:触摸按钮我会打开原生导航(例如Google Maps for Android).我安装了launchnavigator插件:
ionic plugin add uk.co.workingedge.phonegap.plugin.launchnavigator
Run Code Online (Sandbox Code Playgroud)
并在cremony.ts页面内:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { LaunchNavigator, LaunchNavigatorOptions } from 'ionic-native';
@Component({
selector: 'page-ceremony',
templateUrl: 'ceremony.html'
})
export class Ceremony {
constructor(public navCtrl: NavController) {
}
navigate() {
let options: LaunchNavigatorOptions = {
start: ""
};
LaunchNavigator.navigate("London, UK", options)
.then(
success => alert('Launched navigator'),
error => alert('Error launching navigator: ' + error)
);
}
}
Run Code Online (Sandbox Code Playgroud)
制作一个构建npm run build并将其上传到IonicView …
我们使用Cloud Formation来定义一堆Lambda函数:
AWSTemplateFormatVersion: '2010-09-09'
Transform:
- 'AWS::Serverless-2016-10-31'
Resources:
MyLambda:
Type: 'AWS::Serverless::Function'
Properties:
Handler: com.handler::MyLambda
Runtime: java8
CodeUri: .
Description: Some desc
MemorySize: 512
Timeout: 15
Role: !Ref LambdaRole
FunctionName: MyLambda
Events:
MyLambdaEvt:
Type: Api
Properties:
RestApiId: !Ref MyApiDef
Path: /lambda/my
Method: get
MyApiDef:
Type: AWS::Serverless::Api
Properties:
DefinitionUri: s3://a-bucket/api-gateway.yml
StageName: prod
Outputs:
ApiUrl:
Description: URL of your API endpoint
Value: !Join
- ''
- - https://
- !Ref MyApiDef
- '.execute-api.'
- !Ref 'AWS::Region'
- '.amazonaws.com/prod'
Run Code Online (Sandbox Code Playgroud)
CodePipeline生成变更集并执行它.
通过这种方式,所有Lambda函数都已正确更新,但API Gateway端点未正确更新,我们需要s3://a-bucket/api-gateway.yml手动导入和部署YML …
amazon-web-services aws-cloudformation aws-lambda aws-api-gateway aws-codepipeline
如何使用cake语法编写SQL子查询?我知道如何编写简单的查询,但我无法处理子查询.
这是原始查询:
SELECT Assumption.id, Referee.id, Referee.first_name, Referee.second_name
FROM referees AS Referee
INNER JOIN (
SELECT a.id, a.referee_id
FROM assumptions a
WHERE a.season_id =7
) AS Assumption ON Referee.id = Assumption.referee_id
Run Code Online (Sandbox Code Playgroud) Gpx文件是用于跟踪时空信息的XML文档.它看起来像:
<gpx>
<trk>
<segment>
<trkpt lat="...", lon="..."></trkpt>
</segment>
</trk>
</gpx>
Run Code Online (Sandbox Code Playgroud)
除gpx超标签外,每个标签都可以越来越多地被替换.问题是:segment标签的用途是什么?为什么trkpt标签不能直接在父trk标签内收集?组织背后的概念trkpt是segment什么?我在官方gpx网站上搜索了这个,http://www.topografix.com/gpx.asp,但我一无所获!:(
最诚挚的问候MC
我正在使用 AWS Amplify,因为我必须在没有框架(没有 React,没有 Angular:只有普通 JS)的遗留应用程序中引入它的一些功能。
我成功地使用了 Auth 模块,所以我重新创建了一个简单的注册/加入/退出策略。我现在想要的是使用 REST API 模块调用 REST API。所以我使用 API Gateway PetStore 示例创建了一个 API,我将与它进行交互。
所以我创建了配置:
import Amplify from '@aws-amplify/core';
Amplify.configure({
Auth: {
...
},
API: {
endpoints: [
{
name: "PetStore", // name of the API in API Gateway console
endpoint: "https://XXX.execute-api.eu-central-1.amazonaws.com/dev",
region: "eu-central-1",
paths: ['/']
}
]
}
});
Run Code Online (Sandbox Code Playgroud)
和其他地方:
import Api from '@aws-amplify/api-rest';
Api.get('PetStore', '/pets', {})
.then(response => {
console.log(response)
}).catch(error => {
console.log(error);
});
Run Code Online (Sandbox Code Playgroud)
但是,执行时,我总是遇到相同的错误:
API PetStore 不存在
任何的想法?请记住:
我有我自己的好链接http://www.link.com/sometext,现在我会“增强”这个有机会写一些像http://www.link.com/sometext?parameters=myParam因为我需要向由 sometext 调用的文章发送参数。
我可以这样做吗???如何通过 URL 传递参数????我怎样才能得到它的价值?
问候
我有这个方法:
public void Valida(Validazione.IValidator<MyType> validator)
{
// do something...
Validazione.IMapper<MyType> mapper = new MyTypeMapper();
ValidationResult result = validator.Validate(myTypeObj, mapper, new ValidationConfiguration());
// ...continue doing something else
}
Run Code Online (Sandbox Code Playgroud)
我想进行单元测试,所以我会模拟(使用Moq框架)validator来控制Validate方法的结果,所以我写了这个单元测试:
[TestMethod]
public void Long_test_name_as_best_practice()
{
// arrange
MyAggregateRoot aggregateRoot = AggregateRoot.Stub();
var mockedValidator = new Mock<Validazione.IValidator<MyType>>();
mockedValidator.Setup(a => a.Validate(
It.Is<MyType>(x => x.Id == Guid.Parse("3F2504E0-4F89-11D3-9A0C-0305E82C3301")),
It.IsAny<Validazione.IMapper<MyType>>(),
It.IsAny<ValidationConfiguration>()
)).Returns<Validazione.ValidationResult>(x => x = It.IsAny<Validazione.ValidationResult>());
// act
aggregateRoot.Valida(mockedValidator.Object);
// Assert (now showed for readability sake)
}
Run Code Online (Sandbox Code Playgroud)
它构建,听起来我非常正确,但最终我得到:
mscorlib.dll中出现"System.Reflection.TargetParameterCountException"类型的异常但未在用户代码中处理附加信息:参数计数不匹配
我谷歌周围,但我无法理解原因.对我来说似乎很好.
这是异常的堆栈跟踪:
in …Run Code Online (Sandbox Code Playgroud) 我有一个(应该)看起来像这样的WebAPI控制器:
public class MyController : ApiController
{
private IRepository repository;
public MyController(IRepository repository)
{
this.repository = repositor;
}
// REST implementations
}
Run Code Online (Sandbox Code Playgroud)
WebApiConfig 配置如下:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Unity configuration
var container = new UnityContainer();
container
.RegisterType<IRepository , CustomRepository>();
config.DependencyResolver = new UnityResolver(container);
// Web API routes
// CORS
}
}
Run Code Online (Sandbox Code Playgroud)
然后Global.asax.cs我有类似的东西:
public class WebApiApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
GlobalConfiguration.Configure(WebApiConfig.Register);
}
// CORS
protected void Application_BeginRequest(object sender, …Run Code Online (Sandbox Code Playgroud)