小编xab*_*igo的帖子

如何在ListView的renderRow中访问`this`?

我在为一行中的onPress事件运行函数时遇到了麻烦ListView.我正在按照React Native教程尝试从那里继续.它似乎使用ES6语法风格.

这是代码的相关部分.

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 */

import React, {  
  TouchableHighlight,
  AppRegistry,
  Component,
  Image,
  ListView,
  StyleSheet,
  Text,
  View,
  Alert,
} from 'react-native';

class AwesomeProject extends Component {
  constructor(props) {
    super(props);
    this.something = this.something.bind(this); // <-- Trying this, not even sure why
    this.state = {
      dataSource: new ListView.DataSource({
        rowHasChanged: (row1, row2) => row1 !== row2,
      }),
      loaded: false,
    };
  }

//
//Irrelevant code here. Fetching stuff and renderLoadingView
//

  something = function(){
    console.log('something');
    Alert.alert( …
Run Code Online (Sandbox Code Playgroud)

javascript android listview react-native

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

如何在Vanilla JS中使用Apollo Client创建GraphQL订阅

最近,Apollo Client发布了一个websocket订阅功能,但到目前为止,我仅在componentWillMount生命周期挂钩内通过使用subscriptionToMore启动查询来看到它。

这是取自https://dev-blog.apollodata.com/tutorial-graphql-subscriptions-client-side-40e185e4be76#0a8f的示例

const messagesSubscription = gql`
  subscription messageAdded($channelId: ID!) {
    messageAdded(channelId: $channelId) {
      id
      text
    }
  }
`

componentWillMount() {
  this.props.data.subscribeToMore({
    document: messagesSubscription,
    variables: {
      channelId: this.props.match.params.channelId,
    },
    updateQuery: (prev, {subscriptionData}) => {
      if (!subscriptionData.data) {
        return prev;
      }
      const newMessage = subscriptionData.data.messageAdded;
      // don't double add the message
      if (!prev.channel.messages.find((msg) => msg.id === newMessage.id)) {
        return Object.assign({}, prev, {
          channel: Object.assign({}, prev.channel, {
            messages: [...prev.channel.messages, newMessage],
          })
        });
      } else {
        return prev;
      }
    }
  }); …
Run Code Online (Sandbox Code Playgroud)

javascript apollo graphql apollo-client

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

oci_bind_by_name 之后有没有办法查看生成的sql?

我正在开发一个使用 Oracle 作为后端的旧 PHP Web 应用程序。我没有直接访问这个数据库的权限。

在旧应用程序中,他们使用str_replaces 而不是oci_bind_by_name替换 sql 上的变量。我想改变这一点,但我想这样做,同时避免破坏某些东西。所以我在执行sql之前写了一些测试。

我想将旧生成的 sql 与使用后生成的 sql 进行比较,oci_bind_by_name但我找不到查看“绑定”sql 的方法。

有这样的方法吗?

php sql oracle oracle-call-interface

5
推荐指数
0
解决办法
780
查看次数

如何将模拟的可执行模式传递给Apollo Client?

Apollo GraphQL的Mocking示例具有以下代码(见下文).

有趣的是最后一行 - 他们创建并执行graphql查询.但是你通常需要创建ApolloClient对象.我无法弄清楚如何做到这一点.

ApolloClient期望NetworkingInterface作为参数而不是可执行模式.

那么,有没有办法从可执行模式创建ApolloClient,没有NetworkingInterface?

import { makeExecutableSchema, addMockFunctionsToSchema } from 'graphql-tools';
import { graphql } from 'graphql';

// Fill this in with the schema string
const schemaString = `...`;

// Make a GraphQL schema with no resolvers
const schema = makeExecutableSchema({ typeDefs: schemaString });

// Add mocks, modifies schema in place
addMockFunctionsToSchema({ schema });

const query = `
query tasksForUser {
  user(id: 6) { id, name }
}
`;

graphql(schema, query).then((result) => console.log('Got result', result));
Run Code Online (Sandbox Code Playgroud)

graphql react-apollo

4
推荐指数
2
解决办法
1911
查看次数