在Angular中,我在范围内有一个返回大量对象的对象.每个都有一个ID(这是存储在一个平面文件中所以没有DB,我似乎无法用户ng-resource)
在我的控制器中:
$scope.fish = [
{category:'freshwater', id:'1', name: 'trout', more:'false'},
{category:'freshwater', id:'2', name:'bass', more:'false'}
];
Run Code Online (Sandbox Code Playgroud)
在我看来,我有更多关于鱼隐藏的信息,默认情况下ng-show更多,但是当我点击简单显示更多标签时,我想调用该功能showdetails(fish.fish_id).我的功能看起来像:
$scope.showdetails = function(fish_id) {
var fish = $scope.fish.get({id: fish_id});
fish.more = true;
}
Run Code Online (Sandbox Code Playgroud)
现在在视图中显示更多详细信息.但是在搜索完文档后,我无法弄清楚如何搜索该fish数组.
那我该怎么查询数组呢?在控制台中如何调用调试器以便我可以使用该$scope对象?
我需要一个EnumSet数组(通过varargs方法参数给出).首先,我很惊讶在EnumSet(有EnumSet#of(E first, E... rest))中没有varargs构造函数方法.作为一种解决方法,我使用了以下变体:
EnumSet<Options> temp = EnumSet.copyOf(Arrays.asList(options));
Run Code Online (Sandbox Code Playgroud)
但是,这会触发一个java.lang.IllegalArgumentException: Collection is empty.所以,现在我最终得到了以下内容,看起来有些荒谬:
EnumSet<Options> temp = options.length > 0 ?
EnumSet.copyOf(Arrays.asList(options)) :
EnumSet.noneOf(Options.class);
Run Code Online (Sandbox Code Playgroud)
如果当然这可以转移到一些实用方法,但仍然,我问自己是否有一种更简单的方法使用现有的方法?
我在我的应用程序中使用一个简单的自定义指令来修改输入字段:
app.directive('editor', function() {
return {
restrict: 'E',
templateUrl: 'editor.html',
scope: { value: '=' }
};
});
Run Code Online (Sandbox Code Playgroud)
所述editor.html基本上创建一个input与附加控制元件.简化它看起来像这样:
<div>
<input ng-model="value">
<!-- more code here -->
</div>
Run Code Online (Sandbox Code Playgroud)
我使用了访问我的指令<editor value="{{object.name}}"></editor>.这很完美.现在我需要对输入执行不同的验证.使用的必要验证器各不相同,所以我希望能够将实际的验证器传递给我的指令.就像是:
<editor value="{{object.name}}" validator-a validator-b></editor>
Run Code Online (Sandbox Code Playgroud)
要么
<editor value="{{object.name}}" validators="validatorA,validatorB"></editor>
Run Code Online (Sandbox Code Playgroud)
我怎么能实现这一目标?
对于泛型类,我通常更喜欢静态方法而不是构造函数,以避免繁琐的冗余类型参数(下面给出的示例用于说明).
但是在使用自动完成时,Eclipse总是建议使用类型参数,例如:
example (CTRL +空间) Example<T>
然后我必须<T>手动删除,而不是添加我的静态方法,如Example.new().是否有可能更改此行为或完全不同的方便快捷方式以获得更好的工作流程?(我还在使用Eclipse 3,这在4中已经改变了吗?)
static final class Example<T> {
/** Private, use factory method instead. */
private Example() {
}
public static <T> Example<T> create() {
return new Example<T>();
}
}
public static void main(String[] args) {
Example<Integer> example = Example.create();
}
Run Code Online (Sandbox Code Playgroud) 我目前正在评估替换Angular的优点的利弊。RxJS” Observable与普通的Promise,这样我可以使用async和await并获得更直观的代码风格。
我们的典型场景之一:在中加载一些数据ngOnInit。使用Observables,我们可以:
ngOnInit () {
this.service.getData().subscribe(data => {
this.data = this.modifyMyData(data);
});
}
Run Code Online (Sandbox Code Playgroud)
当我改为返回Promisefrom getData(),并使用async和时await,它变为:
async ngOnInit () {
const data = await this.service.getData();
this.data = this.modifyMyData(data);
}
Run Code Online (Sandbox Code Playgroud)
现在,很明显,Angular不会“知道”,而ngOnInit变成了async。我觉得这不是问题:我的应用仍然可以像以前一样工作。但是,当我查看OnInit接口时,显然并未以暗示可以声明该函数的方式声明该函数async:
ngOnInit(): void;
Run Code Online (Sandbox Code Playgroud)
所以-底线:我在这里做什么合理吗?还是会遇到任何无法预料的问题?
我有一个Jersey REST 2.5.1服务,通过Grizzly服务器提供服务.到目前为止一切正常.我想添加一些静态内容,这些内容也通过Grizzly提供,并从我的JAR文件中提供.所以我用CLStaticHttpHandler.当我访问静态资源时,例如我的index.html显式(例如http://localhost:8080/index.html),一切正常.但是,当我尝试访问root时http://localhost:8080,我得到一个404.代码如下所示:
ObjectMapper mapper = new ObjectMapper();
// some configuration stuff here
JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
provider.setMapper(mapper);
ResourceConfig resourceConfig = new ResourceConfig()
.packages("my.restapi.package")
.register(provider);
HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), resourceConfig);
HttpHandler httpHandler = new CLStaticHttpHandler(HttpServer.class.getClassLoader(), "/static/");
httpServer.getServerConfiguration().addHttpHandler(httpHandler, "/");
Run Code Online (Sandbox Code Playgroud)
据我所知,从调试开始,org.glassfish.grizzly.http.server.CLStaticHttpHandler.handle(String, Request, Response)永远不会被调用.任何提示,我如何使index.html可访问的默认页面?
我目前正在开始使用OSGi,iPOJO和iPOJO Annotations,并尝试构建一个在Felix中部署的简单组件.不幸的是,我遇到了各种问题,这些问题花了我几个小时才解决,或者在浪费时间之后我甚至无法解决,如下所示:
我想使用我们使用Maven构建的OSGi包中的现有库.图书馆目前不是"OSGI-ified",我们不打算在中期内这样做.因此,我希望使用...包含此库及其所有依赖项.
<Embed-Dependency>*</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
Run Code Online (Sandbox Code Playgroud)
我现在拥有的是OSGi组件的以下pom.xml文件:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>foo</groupId>
<artifactId>samplecomponent</artifactId>
<packaging>bundle</packaging>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<source>1.6</source>
<target>1.6</target>
<compilerArguments>
<encoding>UTF-8</encoding>
</compilerArguments>
<showDeprecation>true</showDeprecation>
<verbose>true</verbose>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<version>2.3.6</version>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Embed-Dependency>*</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<Embed-Directory>lib</Embed-Directory>
<Export-Package>*</Export-Package>
<_exportcontents>*</_exportcontents>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-ipojo-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>ipojo-bundle</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.ipojo.annotations</artifactId>
<version>1.8.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>foo</groupId>
<artifactId>mylibrary</artifactId>
<version>1.2.3</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project> …Run Code Online (Sandbox Code Playgroud) 我正在玩Selenium Marionette WebDriver.在我的应用程序中,我想顺序打开多个Marionette驱动程序.基本上是这样的:
MarionetteDriver driver = new MarionetteDriver();
// do some stuff
driver.quit();
// a while later
driver = new MarionetteDriver();
// do some stuff
driver.quit();
Run Code Online (Sandbox Code Playgroud)
现在我面临的问题是,只有第一个Marionette实例可以成功启动,并且对于每个后来的尝试,我都会遇到以下异常.问题每次都会发生,并且使用的端口总是在变化,因此显然没有端口冲突.
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.48.2', revision: '41bccdd10cf2c0560f637404c2d96164b67d9d67', time: '2015-10-09 13:08:06'
System info: host: 'qqilihq.local', ip: '192.168.1.2', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.2', java.version: '1.7.0_71'
Driver info: driver.version: …Run Code Online (Sandbox Code Playgroud) 我想在运行时为使用Byte Buddy的抽象类创建一个实现,我面临的问题java.lang.AbstractMethodError是,从创建的实例调用方法时会抛出a.我有一个abstract像这样的现有类(我实际上无法修改,实际上包含更多逻辑):
public abstract class Algorithm {
abstract int execute();
}
Run Code Online (Sandbox Code Playgroud)
使用以下最小样本,我希望我的Algorithm实例返回一个常量值:
Class<?> type = new ByteBuddy()
.subclass(Algorithm.class)
.method(ElementMatchers.named("execute"))
.intercept(FixedValue.value(42))
.make()
.load(classLoader, ClassLoadingStrategy.Default.WRAPPER)
.getLoaded();
Algorithm instance = (Algorithm) type.newInstance();
System.out.println(myInstance.execute());
Run Code Online (Sandbox Code Playgroud)
然而,这会导致以下异常:
Exception in thread "main" java.lang.AbstractMethodError: package.Algorithm.execute()I
Run Code Online (Sandbox Code Playgroud)
(当我实验性地Algorithm改为a时interface,一切正常,但这并不能解决我的具体问题).
遵循 docker-node\xe2\x80\x99s最佳实践,我想以非 root 用户身份运行我的节点应用程序。建议如下:
\n\nFROM node:6.10.3\n...\n# At the end, set the user to use when running this image\nUSER node\nRun Code Online (Sandbox Code Playgroud)\n\n我的简化 Dockerfile 目前如下所示:
\n\nFROM node:6.10.3\nWORKDIR /opt/app\nCOPY package.json .\nRUN npm install\nCOPY . .\nEXPOSE 3000\nUSER node\nCMD ["node", "server.js"]\nRun Code Online (Sandbox Code Playgroud)\n\n因此,在映像构建期间添加的所有文件均归 拥有root,但node server.js以用户身份运行node。这似乎工作正常。
我的问题:chown通过-ing 文件使它们属于node而不是有任何额外的安全好处吗root?即做类似的事情:
RUN chown -R node:node .\nRun Code Online (Sandbox Code Playgroud)\n java ×5
angularjs ×2
javascript ×2
angular ×1
apache-felix ×1
arrays ×1
asynchronous ×1
autocomplete ×1
byte-buddy ×1
bytecode ×1
chown ×1
class ×1
docker ×1
eclipse ×1
enums ×1
enumset ×1
generics ×1
grizzly ×1
interface ×1
jersey-2.0 ×1
maven ×1
node.js ×1
observable ×1
osgi ×1
permissions ×1
promise ×1
selenium ×1
typescript ×1
validation ×1