我正在使用Ajv来验证我的JSON数据.我无法找到一种方法来验证空字符串作为键的值.我尝试使用模式,但它没有抛出适当的消息.
这是我的架构
{
"type": "object",
"properties": {
"user_name": { "type": "string" , "minLength": 1},
"user_email": { "type": "string" , "minLength": 1},
"user_contact": { "type": "string" , "minLength": 1}
},
"required": [ "user_name", 'user_email', 'user_contact']
}
Run Code Online (Sandbox Code Playgroud)
我使用minLength来检查该值是否应至少包含一个字符.但它也允许空的空间.
我正在创建app.router之后调用的中间件,我需要通过路由中间件和路由处理程序访问存储在res.locals对象中的数据.
//...
app.use(app.router);
app.use(myMiddleware);
//...
app.get('/', function(req, res) {
res.locals.data = 'some data';
});
function myMiddleware(req, res, next) {
if (res.locals.data)
console.log('there is data');
else
console.log('data is removed'); // that's what happens
}
Run Code Online (Sandbox Code Playgroud)
问题是res.locals的所有属性在app.router之后变为空.
我试图找到表达或连接的地方清理res.locals以某种方式修补它但到目前为止我找不到它.
我目前看到的唯一解决方案是放弃将这个逻辑放在一个单独的中间件中并将其放在特定于路由的中间件中的想法,其中res.locals可用,但它将使系统更加互连.此外,我有许多路由中间件不会调用下一个路由(当调用res.redirect时),因此我将不得不进行许多更改以使其工作.我非常想避免它并将此逻辑放在一个单独的中间件中,但我需要访问存储在res.locals中的数据.
任何帮助真的很感激.
我有UIView类,它定义了操纵attributedTextUILabel和UITextView属性的方法.
@implementation UIView (replaceAttrText)
-(void) replaceAttrText: (NSString *)str {
if ([self respondsToSelector: @selector(setAttributedText)]) {
NSMutableAttributedString *labelText = [self template];
// change it
[self performSelector:@selector(setAttributedText) withObject: labelText];
}
}
@end
Run Code Online (Sandbox Code Playgroud)
对于UILabel和UITextView,respondsToSelector都返回false(尽管它们响应setAttributedText),如果直接执行setAttributedText而不respondsToSelector检查则引发异常.
当类别直接在UILabel上实现(没有选择器)时,一切正常,但遗憾的是UILabel和UITextView没有具有attributesText属性的共同祖先.
我究竟做错了什么?谢谢!
objective-c uitextview nsattributedstring ios objective-c-category
我在UITableView的第一个单元格中有UITextField,每当它改变时,表也会发生变化.问题是当表更新时,字段失去第一响应者状态并且becomeFirstResponder不再使其成为第一响应者 - 键盘消失.
我[_searchField becomeFirstResponder]在tableView中调用:didEndDisplayingCell:forRowAtIndexPath:但是键盘无论如何都会消失.更新:我之前尝试在cellForRowAtIndexPath中调用了becomeFirstResponder,它也没有用._searchField是连接到该字段的单元类的outlet属性.
我应该在哪里打电话,becomeFirstResponder以便该字段成为第一响应者?或者也许我应该以不同的方式做到这一点,以便该字段不会失去第一响应者状态?我尝试刷新整个表,但是单独的部分(搜索字段在它自己的部分中),但是它不起作用,控制器试图显示不再存在的单元格,所以我更喜欢刷新整个表格.
我知道我可以使用特殊的搜索控制器,但我不喜欢它的设计,所以我用这种方式实现它...
谢谢!
ios ×2
objective-c ×2
ajv ×1
connect ×1
express ×1
json ×1
middleware ×1
node.js ×1
uitableview ×1
uitextfield ×1
uitextview ×1