小编bar*_*lle的帖子

比较 componentDidUpdate 中的 PrevProps

我试图检测道具何时在已componentDidUpdate安装组件内发生变化。我有一个测试(refreshData在下面的代码中)工作正常。是否有可能以一种未被检测到的方式传递道具componentDidUpdate(prevProps)

在 component.js 中:

componentDidUpdate(prevProps){

    //works fine
    if ( this.props.refreshData !== prevProps.refreshData ) {
        if ( this.props.refreshData )
            this.refreshData();
    }

    //these two arent calling
    if ( this.props.selectedCountries !== prevProps.selectedCountries ) {
        if ( this.props.selectedCountries )
            console.log('updated selected countries');
    }

    if ( this.props.selectedLocations !== prevProps.selectedLocations ) {
        console.log('updated selected locations');
    }

}
Run Code Online (Sandbox Code Playgroud)

并在 App.js 中传递如下道具:

selectLocation = (id, type, lng, lat, polydata, name, clear = false) => {

  //console.log(type);
  //console.log(lng);
  //console.log(lat);
  //console.log(polydata);

  let selectedType = …
Run Code Online (Sandbox Code Playgroud)

reactjs react-props

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

Google API - 使用内部IP重定向URI

我正在使用Google日历API创建应用.在我的本地apache安装上,使用localhost:8888/pathtoapp作为重定向URI,一切正常.

我想将应用程序迁移到本地网络上的另一台计算机.我尝试将URI更改为新apache安装的本地ip.我收到以下错误...

Error: invalid_request
Invalid parameter value for redirect_uri: Raw IP addresses not allowed: http://192.168.0.17/pathtoapp/
Run Code Online (Sandbox Code Playgroud)

关于如何使用内部IP作为重定向URI或其他方法的任何想法?

谢谢.

api uri google-api

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

Mapbox - 动态更改集群颜色

我正在使用 mapbox 集群。我想根据另一个函数的某些逻辑更改群集颜色。我正在尝试更改 moveend 上的颜色。理想情况下,我会喜欢这样的东西......

map.on('load', function(){ 

    //data
    map.addSource("surveydata", {
        type: "geojson",
        data: "/surveydata/"+lastweek+"/"+today+"",
        cluster: true,
        clusterRadius: 20 
    });

    map.addLayer({
        "id": "cluster",
        "type": "circle",
        "source": "surveydata",
        "paint": {
            'circle-color': 'rgba(0,0,200,0.2)',
            'circle-radius': 20
        },
        "filter": [">=", "point_count", 2]
    });

});


//recolor clusters
map.on('moveend', function (e) { 

    var colors = ['#ff0000', '#00ff00', '#0000ff'];
    var cluster = map.queryRenderedFeatures({ layers: ["cluster"] });

    //HERE
    for(i = 0; i < cluster.length; i++){

        console.log(cluster[i]); //THIS RETURNS ALL THE CLUSTERS SUCCESSFULLY
        cluster[i].setcolor(randomcolor) //this I am not sure how …
Run Code Online (Sandbox Code Playgroud)

mapbox mapbox-gl-js

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

ES6 类 - 从点击事件调用方法

我是 ECMA 课程的新手。

在下面的代码中,我构建了一个运行良好的按钮类。现在我试图从单击事件侦听器内部调用 prev_image() 方法。我知道“this”指的是按钮实例,但不确定如何从 Gallery 类调用方法。谢谢你的帮助。

class Gallery{

    constructor(){
    }

    draw(){

        //build button
        prevbtn.draw();

        //button listener
        document.getElementById('prevbtn').addEventListener('click', function(){
            this.prev_image();   <--- this errors out
            console.log('pressed'); <--this works
        });

    }

    prev_image(){
        console.log('previous image!');
    }

}
Run Code Online (Sandbox Code Playgroud)

javascript ecmascript-6 es6-class

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

Tensorflow.js LSTM时间序列预测

我正在尝试使用LSTM RNN在Tensorflow.js中构建一个简单的时间序列预测脚本。我显然是ML的新手。我一直在尝试从Keras RNN / LSTM层api改编我的JS代码,这显然是同一回事。从我收集的图层来看,形状等都是正确的。对我在这里做错的任何想法吗?

async function predictfuture(){

    ////////////////////////
    // create fake data
    ///////////////////////

    var xs = tf.tensor3d([
        [[1],[1],[0]],
        [[1],[1],[0]],
        [[1],[1],[0]],
        [[1],[1],[0]],
        [[1],[1],[0]],
        [[1],[1],[0]]
    ]);
    xs.print();

    var ys = tf.tensor3d([
        [[1],[1],[0]],
        [[1],[1],[0]],
        [[1],[1],[0]],
        [[1],[1],[0]],
        [[1],[1],[0]],
        [[1],[1],[0]]
    ]);
    ys.print();


    ////////////////////////
    // create model w/ layers api
    ///////////////////////

    console.log('Creating Model...');

    /*

    model design:

                    i(xs)   h       o(ys)
    batch_size  ->  *       *       * -> batch_size
    timesteps   ->  *       *       * -> timesteps
    input_dim   ->  *       *       * -> input_dim


    */

    const model = tf.sequential(); …
Run Code Online (Sandbox Code Playgroud)

javascript lstm tensorflow rnn tensorflow.js

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

在Jquery中打开/关闭单击事件

我正在尝试打开和关闭点击事件以防止多个函数调用.以下是我的代码.点击是关闭但我似乎无法再打开它.思考?

$("#element").click(function(){
     doit();
     $(this).off('click');
 })

function doit(){

    do stuff...

    //turn click back on
    $("#element").on('click');

}
Run Code Online (Sandbox Code Playgroud)

javascript jquery

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