小编aft*_*eep的帖子

使用controllerAs语法时,将当前范围传递给modalInstance

我正在使用controllerAs语法来避免我的控制器中的$ scope汤,并且还使用ui.bootstrap来呈现模态视图.

我需要打开一个与当前控制器共享相同范围的modalInstace.注入示波器时,您可能会执行以下操作:

var modalInstance = $uibModal.open({
      templateUrl: 'addEditModal.html',
      scope: $scope
    });
Run Code Online (Sandbox Code Playgroud)

但是,由于我没有注入范围,并且使用controllerAs语法,因此无效.

根据我的发现,您需要使用resolve来传递数据,但您必须通过函数显式传递它.有没有办法通过整个范围?

我需要在该模态中执行一些操作,并且传递大量数据似乎有点过分.

不想这样做,因为它看起来很乱......

var modalInstance = $modal.open({
  templateUrl: 'myModalContent.html',
  controller: 'ModalInstanceCtrl',
  resolve: {
    user: function() {
        return vm.user;
    },
    something: function() {
        return vm.something;
    },
    blah: function() {
        return blah;
    }
  }
});
Run Code Online (Sandbox Code Playgroud)

有更好的想法吗?

javascript twitter-bootstrap angularjs bootstrap-modal ui.bootstrap

12
推荐指数
2
解决办法
2万
查看次数

缩进不适用于Custom UITableViewCell

我的项目中有一个简单的Custom UITableViewCell,只是在表格中添加了一个Edit动作.一切似乎都很好,但编辑时缩进不起作用,编辑图标与内容重叠.(更不用说删除按钮)

缩进不适用于自定义单元格
自定义单元格是在界面构建器中创建的,像往常一样使用标准约束,我已经尝试在类中替换layoutSubviews方法,如其他地方所提到的那样没有运气,如下所示;

(void)layoutSubviews
{
[super layoutSubviews];
float indentPoints = self.indentationLevel * self.indentationWidth;

self.contentView.frame = CGRectMake(
                                    indentPoints,
                                    self.contentView.frame.origin.y,
                                    self.contentView.frame.size.width - indentPoints,
                                    self.contentView.frame.size.height
                                    );
}
Run Code Online (Sandbox Code Playgroud)

我还确认子视图实际上在contentView中,并且View和Code中的一切看起来都很好.

Cell还以编程方式设置了indentationLevel/Width,并将掩码自动调整为自动宽度.

作为最后的手段,我可​​以以编程方式创建UITableViewCell,但不认为它可以提供帮助.

根据推荐,我还确保将单元格内容的约束固定到superview.

固定左边的边距

还可以在Code中手动设置de autoResizingMasks,但没有运气

- 编辑:

我已手动将contentView的背景颜色设置为黑色,并发现它在编辑模式下正确缩进,即使没有覆盖"layoutSubviews".事实上,用它做得更好.

在此输入图像描述

但是,正如您所看到的,内容不会缩进.最初我认为单元格的内容(UIImage)不是contentView的子视图,但是对子视图进行了记录,显示它们是.

NSLog(@"%@", self.contentView.subviews);

"<UIImageView: 0xa477030; frame = (23 7; 31 50); autoresize = TM+BM; userInteractionEnabled = NO; layer = <CALayer: 0xa477090>>"
Run Code Online (Sandbox Code Playgroud)

我完全迷失了为什么这种情况在这里不断发生.必须是一些与iOS 6新约束相关的隐藏约束.

objective-c indentation uitableview ios

6
推荐指数
1
解决办法
6753
查看次数

MKAnnotation未在iOS5中被选中

我的应用程序在地图上放置一个图钉,然后选择其使用动画,以便用户有一个视觉线索,可以立即读取标题/副标题.以下代码适用于iOS4和iOS5,但在iOS5中,除非我在selectAnnotation方法中将动画更改为NO,否则不会自动选择注释.

有什么想法吗?

MapAnnotations *pushpin = [[MapAnnotations alloc] initWithCoordinate:coordinate];
pushpin.title = [selectedStation valueForKey:@"name"];
pushpin.subtitle = [selectedStation valueForKey:@"address"];
[stationMap addAnnotation:pushpin];
[stationMap selectAnnotation:pushpin animated:YES];

[pushpin release]; pushpin = nil;
Run Code Online (Sandbox Code Playgroud)

animation mkannotation ios ios5

5
推荐指数
1
解决办法
1403
查看次数

MongoDB:$all 带有空数组...

我正在对包含此类文档的集合运行查询。

{"name": "Daniel", "tags": ["person", "owner", "father"]},
{"name": "Jane", "tags": ["person", "owner", "mother"]},
{"name": "Jimmy", "tags": ["person", "owner", "son"]}
Run Code Online (Sandbox Code Playgroud)

现在,如果我想查找与标签人和所有者匹配的所有文档,我会这样做

var match = ['person', 'owner'];
model.find({'tags': {$all: match}});
Run Code Online (Sandbox Code Playgroud)

现在我需要执行以下操作:

  1. 当匹配有值时,返回与这些值匹配的所有文档(已完成)
  2. 当match为空[]时,返回所有文档。

在单个查询中执行此操作的最有效方法是什么?

提前致谢,

D

find mongodb

5
推荐指数
1
解决办法
2033
查看次数

如何在 swiftyJSON 对象上使用 contains

我试图在 swift 中使用 contains 来查找数组上的值,但是当我使用变量作为谓词时,我得到一个“字符串不可转换为”S.Generator.Element”。

任何人都可以解释这意味着什么以及为什么会发生?

这是使用 swiftyJSON 加载和解析的原始 JSON:

{ "假期" : [ "01/01/2015", "12/01/2015", "23/03/2015", "02/04/2014", "03/04/2015", "01/05" /2015”、“18/05/2015”、“08/06/2015”、“15/06/2015”、“29/06/2015”、“20/07/2015”、“17/08/2015” ", "12/10/2015", "02/11/2015", "16/11/2015", "08/12/2015", "25/12/2015", "02/01/2016" ] }

这有效

var haystack:Array<JSON> = jsonData["holidays"].arrayValue
if(contains(haystack, "01/01/2015")) {
    return true
}
Run Code Online (Sandbox Code Playgroud)

这不起作用:

var haystack:Array<JSON> = jsonData["holidays"].arrayValue
var needle:String = "01/01/2015"
if(contains(haystack, needle)) {
    return true
}
Run Code Online (Sandbox Code Playgroud)

contains swift swifty-json

1
推荐指数
1
解决办法
1424
查看次数