我在使用ng-repeat指令和我自己的自定义指令时遇到了问题.
HTML:
<div ng-app="myApp">
<x-template-field x-ng-repeat="field in ['title', 'body']" />
</div>
Run Code Online (Sandbox Code Playgroud)
JS:
angular.module('myApp', [])
.directive('templateField', function () {
return {
restrict: 'E',
compile: function(element, attrs, transcludeFn) {
element.replaceWith('<input type="text" />');
}
};
});
Run Code Online (Sandbox Code Playgroud)
这里的问题是什么都没有被替换.我想要完成的是2x输入字段的输出,在DOM中完全替换'x-template-field'标签.我怀疑是因为ng-repeat正在同时修改DOM,所以这不起作用.
根据这个 Stack Overflow问题,接受的答案似乎表明这在早期版本的AngularJS(?)中实际上有效.
虽然element.html('...')实际上将生成的HTML注入到目标元素中,但我不希望HTML作为模板标记的子元素,而是在DOM中完全替换它.
基本上,出于与上述相同的原因,我不希望生成的HTML作为重复标记的子元素.虽然它可能在我的应用程序中得体,但我仍然觉得我已经调整了我的标记以适应Angular,而不是相反.
我没有找到任何方法来改变从'template'/'templateUrl'属性中检索到的HTML.我想要注入的HTML不是静态的,它是从外部数据动态生成的.
大概.:-)
任何帮助表示赞赏.
在我的 Maven 项目中,我定义了一堆 Spring 依赖项,我注意到在某些情况下它会选择不同版本的工件,即使它们在我的 pom.xml 中指定相同。
这是概述 mvn dependency:tree
[INFO] com.vrutberg.blogping:blogping:war:1.0-SNAPSHOT
[INFO] +- junit:junit:jar:4.7:test
[INFO] +- javax.servlet:servlet-api:jar:2.4:compile
[INFO] +- com.sun.jersey:jersey-server:jar:1.12:compile
[INFO] | +- asm:asm:jar:3.1:compile
[INFO] | \- com.sun.jersey:jersey-core:jar:1.12:compile
[INFO] +- com.sun.jersey:jersey-bundle:jar:1.12:compile
[INFO] +- javax.ws.rs:jsr311-api:jar:1.1.1:compile
[INFO] +- org.springframework:spring-core:jar:3.0.0.RC3:compile
[INFO] +- org.springframework:spring-expression:jar:3.0.5.RELEASE:compile
[INFO] +- org.springframework:spring-beans:jar:3.0.0.RC3:compile
[INFO] +- org.springframework:spring-aop:jar:3.0.0.RC3:compile
[INFO] +- org.springframework:spring-context:jar:3.0.0.RC3:compile
[INFO] +- org.springframework:spring-context-support:jar:3.0.5.RELEASE:compile
[INFO] +- org.springframework:spring-tx:jar:3.0.5.RELEASE:compile
[INFO] | \- aopalliance:aopalliance:jar:1.0:compile
[INFO] +- org.springframework:spring-orm:jar:3.0.5.RELEASE:compile
[INFO] | \- org.springframework:spring-jdbc:jar:3.0.5.RELEASE:compile
[INFO] +- org.springframework:spring-oxm:jar:3.0.5.RELEASE:compile
[INFO] +- org.springframework:spring-web:jar:3.0.0.RC3:compile
[INFO] +- org.springframework:spring-webmvc:jar:3.0.5.RELEASE:compile
[INFO] | \- org.springframework:spring-asm:jar:3.0.5.RELEASE:compile …Run Code Online (Sandbox Code Playgroud) 我正在iOS应用程序中实现推送通知,正如我所做的那样,我想编写一个UI测试,用于验证应用程序在使用某个推送通知负载启动时是否正确(即应用程序导航)到正确的表视图并突出显示正确的单元格).
可以这样做吗?我似乎无法找到之前已经做过此事或曾经问过这个问题的人.
感谢任何指针.
所以,我有一个看起来像这样的类型:
struct Identifier {
let string: String
}
extension Identifier: Decodable {
public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
string = try container.decode(String.self)
}
}
Run Code Online (Sandbox Code Playgroud)
这种类型的重点是如果我有如下所示的 JSON:
{
"identifier": "abc123",
// more properties ...
}
Run Code Online (Sandbox Code Playgroud)
...它将自动序列化为正确的类型,无需太多努力。Decodable但是,我在不创建包装类型的情况下对这种一致性进行单元测试时遇到了麻烦。
我想做的是这样的:
func testDecodableInit() {
let identifier = try! JSONDecoder().decode(Identifier.self, from: "1".data(using: .utf8)!)
XCTAssertEqual(identifier.string, "1")
}
Run Code Online (Sandbox Code Playgroud)
但显然这不起作用,因为"1"不是有效的 JSON。
是否可以在Decodable不创建包装类型并将数据更改为有效 JSON 的情况下为此一致性编写单元测试?
我正在尝试使用Swift,协议和协议扩展.具体来说,我试图在协议扩展中提供协议的默认实现.这是我的代码:
protocol Proto : class {
func someMethod() -> String
}
extension Proto {
static func create() -> Self {
return ProtoDefaultImpl() as! Self
}
}
class ProtoDefaultImpl : Proto {
func someMethod() -> String {
return "doing something"
}
}
let instance = Proto.create()
let output = instance.someMethod()
print(output)
Run Code Online (Sandbox Code Playgroud)
编译器在我调用的行上抱怨Proto.create(),出现以下错误:error : static member 'create' cannot be used on instance of type 'Proto.Protocol'.
我错过了什么吗?有什么办法可以实现吗?
谢谢.
swift ×3
angularjs ×1
codable ×1
decodable ×1
dependencies ×1
ios ×1
maven ×1
protocols ×1
spring ×1
unit-testing ×1