小编Sim*_*mon的帖子

React Components className中的三元条件

我从json文件中提取数据并尝试仅在满足特定条件时添加类:

    render: function() {
    var gameList = this.props.data.map(function(game) {
        return (
            <li key={game.id} className="list-group-item">
                    {game.home_team_name}
                    <span className="pull-right {game.home.score} > {game.away.score} ? 'highlight':'' ">{game.home.score}</span> <br />
                    {game.away_team_name}
                    <span className="pull-right {game.home.score} > {game.away.score} ? 'highlight':'' ">{game.away.score}</span> <br />
                    {game.status.status}
            </li>   
        );
    });
Run Code Online (Sandbox Code Playgroud)

这个方法似乎只添加了类中的任何内容,如果条件满足则不添加"highlight"类.

还可以在.map方法中再次定义变量以减少重复吗?

我试过 var homeScore = {game.home.score}但没有运气

javascript reactjs

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

UISearchController:searchResultsController 不显示

我对 UISearchController 很陌生,所以如果这是一个愚蠢的问题,请原谅。

我尝试关注这个问题,但无法得到我想要的结果。

在我的中,MapViewController's viewDidLoad我像这样初始化搜索控制器:

searchController = UISearchController(searchResultsController: customViewController)

其中 customViewController 是 UIViewController 的子类,现在有一些文本标签(通过界面构建​​器)。(我这样声明:let customViewController = MyCustomeViewController()

我试图通过隐藏和取消隐藏委托方法中的searchResultsControllerwith来遵循上述链接searchController.searchResultsController?.view.isHidden = false,但没有运气。

结果是一样的:只有视图变暗。

理想情况下,我希望它类似于 Facebook 的应用程序,当您点击搜索栏时,它会显示不同的视图。

我searchResultsController在委托中打印了对象,willPresentSearchController它确实将其指示为MyCustomViewController.

我在这里遗漏了什么还是这不是正确的方法?

在此处输入图片说明

ios swift uisearchcontroller

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

ReactJS:this.props.data.map不是一个函数

我正在尝试从 .json 文件获取数据并通过视图显示结果。以下是 Scoreboard.json 文件。

{
"subject":"scoreboard",
"copyright":"Copyright 2015",
"data":
   "games":{
     "next_day_date":"2015-07-22",
     "modified_date":"2015-08-04T07:34:50Z",
     "month":"07",
     "year":"2015",
     "game":[
        {
           "game_type":"R",
           "double_header_sw":"N",
           "location":"Some City, State",
        }, 
        {
           "game_type":"R",
           "double_header_sw":"N",
           "location":"Another City, Another State"
        }
     ]
   }
Run Code Online (Sandbox Code Playgroud)

我只需要“数据”字段,而不需要“主题”或“版权”字段,并且可以通过下面的 ajax 请求来完成此操作。

{
"subject":"scoreboard",
"copyright":"Copyright 2015",
"data":
   "games":{
     "next_day_date":"2015-07-22",
     "modified_date":"2015-08-04T07:34:50Z",
     "month":"07",
     "year":"2015",
     "game":[
        {
           "game_type":"R",
           "double_header_sw":"N",
           "location":"Some City, State",
        }, 
        {
           "game_type":"R",
           "double_header_sw":"N",
           "location":"Another City, Another State"
        }
     ]
   }
Run Code Online (Sandbox Code Playgroud)

我将状态传递给接收文件,但是,当我尝试调用它时,我收到一个TypeError: this.props.data.map is not a function

	getInitialState: function() {
		return {data: []};
	},
	componentDidMount: function() …
Run Code Online (Sandbox Code Playgroud)

javascript jquery json reactjs

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

Swift 2.2 HealthKit - 调用可以抛出,但它没有标记为'try'并且没有处理错误

我正在按照此处的健康工具包教程进行操作

它使用的是旧版本的Swift(1.2),我正在尝试将其转换为最新版本(撰写本文时为Swift 2.2)

错误表明我需要进行do, catch, and try处理但是,它仍然会抛出相同的错误Call can throw, but it is not marked with 'try' and the error not handled?

我在下面添加了我的尝试.使用Swift 2.2,我还需要使用最新的检查错误if error != nil吗?或者现在在处理中do, catch, try处理?

var error:NSError?
var age:Int?

// 1. Request birthday and calculate age
if let birthDay = healthKitStore.dateOfBirth()
{
  do {
    let today = NSDate()
    let calendar = NSCalendar.currentCalendar()
    let differenceComponents = NSCalendar.currentCalendar().components(.CalendarUnitYear, fromDate: birthDay, toDate: today, options: NSCalendarOptions(0) )

    try! age = differenceComponents.year …
Run Code Online (Sandbox Code Playgroud)

ios swift healthkit swift2.2

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