小编Mat*_*ung的帖子

异步等待axios不返回错误

我正在使用异步等待axios并且我遇到了错误处理问题.使用正常的promise(下面的例子2),我可以在杀死我的本地服务器时获得一个错误对象.但是,使用异步等待,error来自未定义(下面的示例1)有谁知道为什么会这样

const instance = axios.create({
  baseURL: 'http://localhost:8000',
  timeout: 3000,
})

// example 1
try {
   await instance.get('/data/stores')
} catch (error) {
  console.log(error) // error is not defined
}
// example 2
return instance.get('/data/stores').catch(error => {
  console.log(error) // error is normal axios error
})
Run Code Online (Sandbox Code Playgroud)

javascript async-await axios

9
推荐指数
2
解决办法
4413
查看次数

在swift中更改嵌套字典中的值

我想知道为什么在设置嵌套字典的值时,包含字典不反映这些更改?在line3上,是返回的字典的副本?

var dic = Dictionary<String, AnyObject>()  // line1
dic["key"] = ["a":"a"] // line2
var dic2 = dic["key"] as Dictionary<String, String> // line3
dic2["a"] = "b" // line4
dic // key : ["a":"a"], would expect ["a":"b"]
Run Code Online (Sandbox Code Playgroud)

swift

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

动态更改React Native Flat List中的列数

我有一个FlatList我想根据方向更改列数的地方.但是,当我这样做时,我会看到红色屏幕.根据红屏错误消息,我不太确定我应该如何更改关键道具.任何帮助表示赞赏.

      // dynamically changing number of columns
      const numCols = orientation === constants.PORTRAIT ? 3 : 8

      <FlatList
        keyExtractor={(_, i) => i}
        numColumns={numCols} // assigning the number of columns
        horizontal={false}
        renderItem={({ item }) => <ListItem imageUrl={item.url} />}
      />}
Run Code Online (Sandbox Code Playgroud)

红屏死机

reactjs react-native react-native-flatlist

6
推荐指数
4
解决办法
5504
查看次数

在Dictionary扩展中引用self

我正在尝试扩展词典,但不能用键引用自己.我很困惑为什么会这样.

extension Dictionary {
    func foo() {
        var result = self["key"]
    }
}
Run Code Online (Sandbox Code Playgroud)

我收到此错误:类型'DictionaryIndex'不符合协议'StringLiteralConvertible'

如果有人有任何见解,将不胜感激.

swift

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

React Native mobx 绑定到 FlatList 不起作用

我有一个 RN (0.44.2) mobx(3.1.10) 应用程序,它使用FlatList. 我基本上遵循https://blog.callstack.io/write-react-native-apps-in-2017-style-with-mobx-e2dffc209fcb

当使用我自己的商店时,与示例相反,我必须使用它toJS()才能渲染 FlastList

    // renders list
    <FlatList
      data={this.props.giphyStore.images.toJS()}
      keyExtractor={(_, i) => i}
      renderItem={({ item }) => <Text>found the data</Text>}
    />

    // does not render list
    <FlatList
      data={this.props.giphyStore.images}
      keyExtractor={(_, i) => i}
      renderItem={({ item }) => <Text>did not find the data</Text>}
    />
Run Code Online (Sandbox Code Playgroud)

我真的很难弄清楚为什么toJS()在某些情况下可能需要而不是在其他情况下。

我的商店正在设置可观察的图像,如下所示

async getImageList(query: string) {
  try {
    const requestURL = `${constants.GIPHY_ENDPOINT}${query}`
    const response = await axios.get(requestURL);
    const imgs = response.data.data.map((item) => {
      return { id: …
Run Code Online (Sandbox Code Playgroud)

mobx mobx-react react-native-flatlist

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

如何在xcode 6.1.1中打印出一个Dictionary的值

在Swift中调试时,我在读取变量时遇到了问题.在这个例子中,我试图打印出info从图像选择器返回的对象的值.(请参阅dropbox截图链接)

println从屏幕截图第19行可以看出使用正常.它打印输出的第一块东西.

在那之后,我尝试了一个po info以及突出显示变量并单击眼睛来打印描述.这两个都是空的{},这对我来说没有意义,因为那里有明显的东西.

所以我的问题是,是否有一个lldb命令或简单的方法来查看/打印出变量的值 - 与空相反{}我发现我无法一致地观察我变量的值,这是令人沮丧的.

https://dl.dropboxusercontent.com/u/45836281/debug.png

xcode swift

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