我想要一个自定义控件,用于ngModel.$formatters在服务器依赖项加载后立即格式化数据.在我的情况下,它需要加载查找表以从一种id转到另一种id.$modelValue商店一件事$viewValue显示另一件事.相当直接的东西.
诀窍是,如果我的查找表没有加载,我不能格式化为$ viewValue.
加载数据后,我需要执行以下操作:
ngModel.$formatters.push(myFormatter)$modelValue -> $formatters -> $viewValue$render()不起作用,这只是将值移动$viewValue到UI控件.
$rollbackViewValue()看起来很有希望,但这只是在一个不稳定的版本(1.3.0-beta.18).
代码示例:
mappingTable.load().then(function(data){
mappingData = data;
ngModel.$formatters.push(myFormatter); // needs mappingData in order to function
// TODO: Tell ngModel to run the existing $modelValue through $formatters to calculate a new $viewValue and $render it
//ngModel.$render() // doesn't work, only puts the $viewValue in the DOM element.
});
Run Code Online (Sandbox Code Playgroud) 我想利用html5的改进语义.我正在创建一个搜索区域,搜索区域应该有一个背景并包含与搜索相关的内容,例如自动填充和搜索提示.
关于什么类型的元素应该包含在搜索区域中,是否存在一些共识?
标记是这样的:
<?whatElement?>
<input type="search" placeholder="Search for a name or ID..." required />
<a href="#" class="search button">Search</a>
</?whatElement?>
Run Code Online (Sandbox Code Playgroud)
谢谢你的想法.
为了开发和调试移动和平板电脑应用程序,我希望能够让我的鼠标模拟touchstart,touchmove和touchend.
我发现了两种可能性:
Phantom Limb http://www.vodori.com/blog/phantom-limb.html (似乎不起作用)
ChromeTouch https://chrome.google.com/webstore/detail/ncegfehgjifmmpnjaihnjpbpddjjebme (滚动页面,但不触发触摸事件)
有没有人知道会在桌面webkit浏览器中触发触摸事件的插件?
构建单页/胖客户端应用程序,我想知道使用http://piwik.org/进行包含和跟踪的最佳实践是什么
我想以一种体系结构合理的方式使用Piwik,并且将来可以替换为不同的库.
看来Piwik跟踪有两个基本选项:
_paq使用命令填充全局数组,然后加载脚本(我不清楚如何记录未来的"页面"视图或更改变量)var myTracker = Piwik.getTracker()_paq 做法:myApp.loadAnalytics = function() { /* dynamically insert piwik.php script */ }
myApp.track = function(pageName) {
window._paq = window._paq || [];
_paq.push(['setDocumentTitle', pageName]);
_paq.push(["trackPageView"]);
}
myApp.loadAnalytics()
// Then, anywhere in the application, and as many times as I want (I hope :)
myApp.track('reports/eastWing') // Track a "page" change, lightbox event, or anything else
Run Code Online (Sandbox Code Playgroud)
.getTracker() 做法:myApp.loadAnalytics = function() { /* dynamically insert piwik.php script */ }
myApp.track …Run Code Online (Sandbox Code Playgroud) javascript analytics matomo fat-client single-page-application
我有一个在iOS 5时代写过的视图控制器,我正在尝试将其转换为iOS 7.阅读iOS 7过渡指南并在SO上进行探索后,我发现我需要设置新的iOS 7属性edgesForExtendedLayout以UIRectEdgeNone防止我的一个自定义子视图在iOS 7上出现比在iOS 6上显示的高49个像素.但是,在设置该属性后,我的自定义子视图在iOS 7上仍然显示高出49个像素,我不知道还有什么我需要做的.这是我添加到viewDidLoad方法中的简单代码...
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
self.edgesForExtendedLayout = UIRectEdgeNone;
}
Run Code Online (Sandbox Code Playgroud)
这是用于创建和添加在iOS 7上显得更高的自定义子视图的代码...
CGRect customControlFrameRect = {{0.0f, 240.0f}, {100.0f, 100.0f}};
self.customControl = [[MyCustomControl alloc] initWithFrame:customControlFrameRect];
self.customControl.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
[self.view addSubview:self.customControl];
Run Code Online (Sandbox Code Playgroud)
另一个重要的细节,如果它有帮助,这个视图是从一个nib文件创建的,但iOS 7上比iOS 6更高的自定义子视图是viewDidLoad我设置edgesForExtendedLayout属性后创建和编程添加的唯一子视图.无论是否设置egdesForExtendedLayout属性,从笔尖创建的所有其他子视图都不会受到影响.
我的两个问题是......
提前感谢您的智慧!
我有两个大的,嵌套的javascript对象,我想比较它们并创建一个只代表差异的对象.我打算用它来创建一个PATCH请求.
给定oldObj和newObj:
newObj应该在diff中oldObj应该在diff中newObj如果值是数组,字符串或数字,则两个对象上的属性应使用值这可能看起来像重复,但我认为不是.此解决方案(1)仅为一级深度(下面的答案是非递归的,在阵列上爆炸,并且不是双向的).这个解决方案(2)返回不变的属性不是双向的.
目标输入/输出:
diff({a:1},{a:0}); // {a:0}
diff({a:1},{b:1}); // {a:1,b:1}
diff({
a: { x: 1 },
b: 1
},
{
a: { x: 0 },
b: 1
}) // {a:{x:0}}
diff({a:[1,3,5,7]},{a:[1,3,7]}); // {a:[1,3,7]}
Run Code Online (Sandbox Code Playgroud)
我正在使用从解决方案1修改的以下方法.它符合所有条件,diff({a:1},{b:1}) // {a:1,b:1}因为它只在一个方向上进行比较.
jsonDiff = function(oldObject, newObject) {
var diff, i, innerDiff;
diff = {};
for (i in newObject) {
innerDiff = {};
if (_.isArray(newObject[i])) {
if …Run Code Online (Sandbox Code Playgroud) 我有一个自定义的UIView,我想动画它的backgroundColor属性.这是一个动画属性的UIView.
这是代码:
class ETTimerUIView: UIView {
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
// other methods
func flashBg() {
UIView.animateWithDuration( 1.0, animations: {
self.backgroundColor = UIColor.colorYellow()
})
}
override func drawRect() {
// Something related to a timer I'm rendering
}
Run Code Online (Sandbox Code Playgroud)
此代码导致动画跳过并且颜色立即更改:
self.backgroundColor = UIColor.colorYellow() // Changes immediately to yellow
Run Code Online (Sandbox Code Playgroud)
如果我为alpha设置动画,则会按预期在1秒内激活1到0:
self.alpha = 0 // animates
Run Code Online (Sandbox Code Playgroud)
在这种情况下,如何设置背景颜色变化的动画?
drawRect块backgroundColor动画,但尚未提供答案.drawRect和animateWithDuration,但我不太明白.我想我需要制作一个单独的视图 - 这应该放在同一个视图控制器的故事板中吗?以编程方式创建?
对不起,我是iOS和Swift的新手.
我正在寻找一种方法来捕获多种类型的错误catch.我已经尝试过fallthrough将逗号分隔的样式与switch语句分开,但都不起作用.该文档只字不提追赶数倍,但pattern 1.我不清楚哪种模式语法可以在这里工作.
错误定义(示例):
enum AppErrors {
case NotFound(objectType: String, id: Int)
case AlreadyUsed
}
Run Code Online (Sandbox Code Playgroud)
作品:
do {
//...
} catch AppErrors.NotFound {
makeNewOne()
} catch AppErrors.AlreadyUsed {
makeNewOne()
} catch {
print("Unhandled error: \(error)")
}
Run Code Online (Sandbox Code Playgroud)
不编译,是否可以做这样的事情?
do {
//...
} catch AppErrors.NotFound, AppErrors.AlreadyUsed {
makeNewOne()
} catch {
print("Unhandled error: \(error)")
}
Run Code Online (Sandbox Code Playgroud) 我有一些我希望跨项目的快速扩展.
我想避免类别污染,除非要求扩展.
是否可以编写它们以便它们仅在我完成某个导入时才适用,例如:
import MySwiftExtensions
// Use custom extensions
let x = [1,3,5,7].average()
let y = [1,3,5,7].firstWhere { $0 > 3 }
let z = "campervan".make1337()
Run Code Online (Sandbox Code Playgroud)
我可以将它们写成包含在单个字母类中的静态方法(例如:ø.average([1,3,5,7]),像lodash)来实现相同的功能,但有时你会从实例方法中获得更简洁的用法.
我有几个笨拙的任务,我试图分享这些任务的全局变量,我遇到了问题.
我编写了一些自定义任务,根据构建类型设置正确的输出路径.这似乎是正确的设置.
// Set Mode (local or build)
grunt.registerTask("setBuildType", "Set the build type. Either build or local", function (val) {
// grunt.log.writeln(val + " :setBuildType val");
global.buildType = val;
});
// SetOutput location
grunt.registerTask("setOutput", "Set the output folder for the build.", function () {
if (global.buildType === "tfs") {
global.outputPath = MACHINE_PATH;
}
if (global.buildType === "local") {
global.outputPath = LOCAL_PATH;
}
if (global.buildType === "release") {
global.outputPath = RELEASE_PATH;
}
if (grunt.option("target")) {
global.outputPath = grunt.option("target");
}
grunt.log.writeln("Output folder: …Run Code Online (Sandbox Code Playgroud)