小编Soh*_*dya的帖子

Heroku上的Redis将多个哈希键保存为一个.但在本地redis db上可以

我们遇到了heroku-redis的问题,其中新的哈希键以相同的值保存

scan 0在heroku 1) "0" 2) 1448734352609, 1448734366659, 1448734356829 上给出了以下内容, 而在localhost上我们有以下内容: 1) "0" 2) 1) "1448734352609" 2) "1448734366659" 3) "1448734356829"

我们添加哈希的代码是相同的,并且没有更改.我们正在使用redis NPM模块.只是无法弄清楚为什么它不能在Heroku上工作.帮助将不胜感激.

链接到我的项目

希望我已经彻底了解了这些信息,如果您需要,请告诉我.:)

heroku redis node.js

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

字典到JSON在swift 3中被序列化两次

我正在尝试使用以下字典进行发布请求,该字典转换为JSON

    let store = [
        "newTask" : [
            "project_name": "iOS",
            "total_time":0,
            "color":"blue"
        ]
    ]
Run Code Online (Sandbox Code Playgroud)

我使用以下代码将其序列化,然后使用以下选项发出http-POST请求:

        let jsonData = try? JSONSerialization.data(withJSONObject: store)

        var request = URLRequest(url: URL(string: "http://localhost:3000/store")!)
        request.httpMethod = "POST"
        request.httpBody = jsonData
Run Code Online (Sandbox Code Playgroud)

我还使用以下db.json文件运行json-server https://github.com/typicode/json-server

{
 "store": [
  {
    "id": 0,
    "ios": {
      "project_name": "iOS",
      "total_time": 0,
      "color": "blue"
    }
  },
  {
    "id": 1,
    "elm": {
      "project_name": "elm",
      "total_time": 0,
      "color": "blue"
    }
  }
]
}
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是db中新添加的项看起来不正确,格式如下:

{
  "{\"newTask\":{\"project_name\":\"iOS\",\"total_time\":0,\"color\":\"blue\"}}": "",
  "id": 10
},
Run Code Online (Sandbox Code Playgroud)

我不确定为什么它将整个字典序列化为键,然后将空字符串作为值.

更新

以下是将此发布到服务器的代码:

let task = URLSession.shared.dataTask(with: …
Run Code Online (Sandbox Code Playgroud)

json nsdictionary nsjsonserialization swift

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

scrollIntoView使用React引用

我们正在尝试在用户关闭另一个组件时滚动到特定组件.

我们的示例与下面的示例非常类似,取自https://reactjs.org/docs/refs-and-the-dom.html#exposing-dom-refs-to-parent-components

function CustomComponents(props) {
  const items = [1,2,3,4].map((x, i) => return (
    <div ref={props.inputRef} key={i}>
     x + hello
    </div>
  )

  return (
    <div>
      { items }
    </div>
  );
}

function Parent(props) {
  return (
    <div>
      <CustomComponents inputRef={props.inputRef} />
    </div>
  );
}


class Grandparent extends React.Component {
  render() {
    return (
      <Parent
        inputRef={el => this.inputElement = el}
      />
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

我们正在提供大量的卡片,并希望能够通过调用滚动到特定的卡片 this.refs[elem].scrollIntoView()

但我们的问题是调用this.refs在所有级别返回一个空对象,因此我们无法附加到特定元素,然后在用户返回查看此组件时触发它.

想要一些人如何解决这个问题.

javascript dom ref reactjs react-dom

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

向Github API发出Post请求以创建问题是行不通的

在过去的几天里,我一直试图向github api提出这个帖子请求,但不幸的是,响应又回来了"坏消息"

这是我们在post请求中使用节点中的https请求发送的代码段 -

这是发布数据

var issueData = JSON.stringify({
  "title":title,
  "body":comment
});
Run Code Online (Sandbox Code Playgroud)

这是选项文件

var options = {
  host: 'api.github.com',
  path: '/repos/sohilpandya/katasohil/issues?access_token='+sessions.token,
  headers: {
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0',
  },
  method: 'POST'
};
Run Code Online (Sandbox Code Playgroud)

这是https请求

var requestaddIssue  = https.request(options, function(responseFromIssues){
  responseFromIssues.setEncoding('utf8');
  responseFromIssues.on('data', function(chunk){
    console.log('>>>>chunk>>>>>',chunk);
    issueBody += chunk;
  });
  responseFromIssues.on('end',function(issueBody){
    console.log(issueBody);
  });
});
requestaddIssue.write(issueData);
requestaddIssue.end();
Run Code Online (Sandbox Code Playgroud)

我尝试了另一种方法,其中用户的身份验证令牌位于标题中

'Authentication': 'OAuth '+ sessions.token (where we are storing token inside sessions)
Run Code Online (Sandbox Code Playgroud)

但是块响应似乎总是在控制台日志中返回以下内容.

{
 "message": "Not Found",
 "documentation_url": "https://developer.github.com/v3/issues/#create-an-issue"
}
Run Code Online (Sandbox Code Playgroud)

我在apigee尝试过相同的操作,似乎工作正常并返回正确的响应.希望有人可以在上面的代码中找到导致此错误消息错误的次要错误.

node.js github-api

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

iOS无法删除通知观察者.Deinit没有被召唤

我有一个类似你可以在下面看到的UIView:

class ViewTaskViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
override func viewDidLoad() {
    super.viewDidLoad()
    subscribeToNotifications()
}

func subscribeToNotifications() {
    let notification = NotificationCenter.default
    notification.addObserver(forName: Notification.Name(rawValue: "TimerUpdated"), object: nil, queue: nil, using: handleUpdateTimer)
    print("Subscribed to NotificationCenter in ViewTaskViewController")
}

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    print("TUFU TUFU TUFU")
    NotificationCenter.default.removeObserver(self)
}

deinit {
    print("DENINT")
}

@objc func handleUpdateTimer(notification: Notification) {
    if let userInfo = notification.userInfo, let timeInSeconds = userInfo["timeInSeconds"] as? Int {

        withUnsafePointer(to: &self.view) {
            print("We got timeeeeee \(timeInSeconds) \($0)")
        }

       //do something …
Run Code Online (Sandbox Code Playgroud)

memory-leaks nsnotification ios swift deinit

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

React Google Maps无法设置滚动缩放

我一直试图将滚动参数上的缩放设置为关闭,但没有运气将该功能关闭.

我正在使用react-google-maps组件.链接如下.

https://github.com/sohilpandya/Bidlt/blob/master/src/js/components/builder/overview-google-map.js

如果有人可以关注它并帮助我弄清楚放大缩放的位置,我将不胜感激.

google-maps reactjs

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