小编zl2*_*3cn的帖子

ReactJS中的子父组件通信

我喜欢在事件触发时将属性属性/ props/state值从子组件发送到父组件onDrag.我找不到合适的文件.

这是我的代码:

/*** @jsx React.DOM */
var APP=React.createClass({
  getInitialState:function()
  {
     return {url:'http://www.youtube.com/embed/XGSy3_Czz8k'}
  },
  handleDrag:function(vidurl)
  {
    alert(vidurl);    //i need to get child component url here.
  },
  render:function(){
    return  <div>
               <VideoFrame  src={this.state.url} />
               <hr/>
           <videos handle={this.handleDrag(vidurl)} />
        </div>
  }
});

var VideoFrame=React.createClass({
  render:function(){
    return  <div>
          <iframe width="420" height="315"  src={this.props.src}>
          </iframe>     
        </div>
  }
});

var videos=React.createClass({
  getInitialState:function()
  {
    return {vidurl:'http://www.youtube.com/embed/XGSy3_Czz8k'}
  },
  render:function()
  {
    return  <img src="http://upload.wikimedia.org/wikipedia/en/a/a6/Size_Small.PNG" onDrag={this.props.handle.bind(this.state.vidurl)}></img> //trying to send state value from here
  }
});

React.renderComponent(<APP />, document.body);      
Run Code Online (Sandbox Code Playgroud)

我希望我的代码清楚.

javascript reactjs react-jsx reactjs-native

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

将自定义事件与Vue 2和JSX绑定

我想在根标记上绑定自定义事件,而不是在中绑定它mounted()。所以我尝试下面的代码:

render (h) {
  return (
    <div on-custom-event={this.handleCustomEvent}></div>
  )
}
Run Code Online (Sandbox Code Playgroud)

但是,当我使用Chrome运行它时,我发现它custom-event绑定到DOM,无法使用触发$emit,但是使用VueJS 2的模板语法很容易做到:

<template>
   <div @custom-event="handleCustomEvent"></div>
</template>
Run Code Online (Sandbox Code Playgroud)

请帮助我解决这个问题,谢谢!

javascript vue.js vuejs2

6
推荐指数
2
解决办法
1948
查看次数

无法引用默认构造函数 -- 这是 VS 中的已删除函数

我尝试从Visual Studio 2015 社区中的https://github.com/zcbenz/BPlusTree编译代码。代码可以在gcc中编译,但是在VS中,我得到了

“bpt::internal_node_t”的默认构造函数不能被引用——它是一个被删除的函数

结构是这样的:

struct internal_node_t {
    typedef index_t * child_t;

    off_t parent; /* parent node offset */
    off_t next;
    off_t prev;
    size_t n; /* how many children */
    index_t children[BP_ORDER];
}; 
Run Code Online (Sandbox Code Playgroud)

中随处可见的引用bpt.cc,像这样

internal_node_t parent;
Run Code Online (Sandbox Code Playgroud)

我真的不明白这个消息是什么意思。如何使代码在VS中编译?

一些类型定义更新:

struct key_t {
    char k[16];

    key_t(const char *str = "")
    {
        bzero(k, sizeof(k));
        strcpy_s(k, str);
    }
};
typedef unsigned int     size_t;

struct index_t {
    key_t key;
    off_t child; /* child's offset */
};
Run Code Online (Sandbox Code Playgroud)

我使用off_tin<sys\types.h> …

c++ visual-studio

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

为什么 asyncio 使用 aiohttp 发出请求仍然使用线程

我认为它ayncio的使用coroutine与线程无关,因为coroutine它是在程序调度程序下运行的一种“线程”,所以每个进程应该只有1个线程运行。但是当我运行使用 python-aiohttp 发出 100 万个请求中的示例时,代码如下所示:

# modified fetch function with semaphore
import random
import asyncio
from aiohttp import ClientSession

async def fetch(url, session):
    async with session.get(url) as response:
        delay = response.headers.get("DELAY")
        date = response.headers.get("DATE")
        print("{}:{} with delay {}".format(date, response.url, delay))
        return await response.read()


async def bound_fetch(sem, url, session):
    # Getter function with semaphore.
    async with sem:
        await fetch(url, session)


async def run(r):
    url = "http://localhost:8080/{}"
    tasks = []
    # create instance of …
Run Code Online (Sandbox Code Playgroud)

python python-asyncio aiohttp

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

具有HTML5音频属性的vuejs

我正在使用Vuejs制作音频控制面板,我想将currentTime属性绑定到一个computed值,所以我写

  computed: {
    'currentTime': {
      cache: false,
      get: function () {
        return document.getElementById('player').currentTime
      }
    }
  },
Run Code Online (Sandbox Code Playgroud)

这是我的audio标签:

  <audio :src="musicSrc" preload="auto" id="player">
    <p>Your browser does not support the <code>audio</code> element.</p>
  </audio>
Run Code Online (Sandbox Code Playgroud)

我可以得到它ready

  ready () {
    this.player = document.getElementById('player')
  },
Run Code Online (Sandbox Code Playgroud)

我可以控制它 methods

play: function () {
  this.player.play()
},
Run Code Online (Sandbox Code Playgroud)

但是当我{{ currentTime }}在模板中使用时

计算表达式“ currentTime”时出错。

未捕获的TypeError:无法读取null的属性“ currentTime”

javascript audio html5 vue.js

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