草庐IT

jump_to_this_location

全部标签

javascript - React - 将 `this` 绑定(bind)到导入的函数

在我的React应用程序中,我希望能够跨几个类似的组件访问一些函数...但是,我想将this绑定(bind)到共享函数这样他们就可以做一些事情,比如更新组件状态等......但是,似乎导入函数然后尝试以“典型”React方式绑定(bind)this是行不通的。这是我想要完成的示例-在这种情况下,单击呈现的按钮将从导入的共享函数文件中调用函数并更新组件状态://shared_functions.jsconstsharedFunctions={testFunction=()=>{this.setState({functionWasRun:true})}}//MyComponent.jsxi

javascript - 类型错误 : Converting circular structure to JSON in nodejs

我正在使用node.js的请求包代码:varformData=({first_name:firstname,last_name:lastname,user_name:username,email:email,password:password});request.post({url:'http://localhost:8081/register',JSON:formData},function(err,connection,body){exports.Register=function(req,res){res.header("Access-Control-Allow-Origin",

javascript - Jquery 时间选择器 : How to dynamically change parameters

我正在使用JqueryTimepicker。我有两个输入字段-接受时间。我正在根据documentation使用JqueryUI计时器$('#startTime').timepicker({'minTime':'6:00am','maxTime':'11:30pm','onSelect':function(){//changethe'minTimeparameterof#endTime我希望当第一次选择timePicker时,第二个的“minTime”参数会发生变化。基本上我正在尝试收集某些事件的开始时间和结束时间。我希望第二个输入框显示第一个输入字段(开始时间)本身的值的选项。

javascript - 在 React-Native 中访问 this.state

嗨,我是React的新手,请多多包涵。我想将地理位置存储为一个状态。看起来很漂亮,因为位置的任何变化都会触发渲染,这正是我想要的。在开发过程中,我有一个按钮,通过访问lastPosition手动触发事件。但是当我这样做的时候。状态是“未定义”。有什么线索吗?exportdefaultclassFetchProjectextendsComponent{constructor(props){super(props);this.state={initialPosition:'unknown',lastPosition:'unknown',};}//codethatsetslastpositi

javascript - 如何在 Typescript 的回调函数中访问 'this'?

这个问题在这里已经有了答案:Howtoaccessthecorrect`this`insideacallback(13个答案)关闭6年前。一旦调用回调,我试图将在类开头声明的变量(bool值)设置为true,但我不断收到TypeScript错误。这里是错误:TypeError:Cannotsetproperty'nonReceived'ofundefined这是我的代码:finalizeToken(){braintree.setup(JSON.parse(this.finalToken),'dropin',{container:'dropin-container',defaultFir

javascript - undefined 不是一个对象(评估 '_this2.props.navigation.navigate' ) - React Native

我真的无法让我的导航正常工作。我正在使用react-navigation(StackNavigator)。这是我的结构:http://i.imgur.com/IKExx9g.png我的导航在HomeScreen.js中工作:我从HomeScreen.js导航到NewScreen.js没有问题。App.js:importReactfrom'react';import{StatusBar,AppRegistry}from'react-native';import{StackNavigator}from'react-navigation';import{HomeScreen}from'./s

Javascript 表单提交 : Object doesn't support this property or method (IE7)

我正在尝试使用javascript提交表单。Firefox工作正常,但IE在此函数的提交行上提示“对象不支持此属性或方法”:functionsubmitPGV(formName,action){vargvString="";pgVisibilities.each(function(pair){gvString+=pair.key+":"+pair.value+",";});$('pgv_input').value=gvString;varform=$(formName);form.action=action;form.submit();}在这里调用:这是表格:有什么想法吗?

javascript - Mocha 和 this 上下文

所以我有这段代码:describe('maindescribe',function(){afterEach(function(){//this.prop===undefined});describe('sub',function(){it('shoulddosomething',function(){this.prop='test';});});});我不知道为什么mainafterEach中的this.prop是undefined因为下面的代码按预期工作:describe('maindescribe',function(){afterEach(function(){//this.pr

javascript - 'this'关键字,不清楚

我对以下代码中的“this”关键字感到困惑,有两个“this”:varFoo=function(string){this.name=string//1st-this}Foo.prototype.get_name=function(){returnthis.name//2nd-this}varmyFoo=newFoo('John')the_name=myFoo.get_name()'the_name'等于'John',原型(prototype)方法通过返回this.name得到名字。但是谁能给我解释一下1st-this和2nd-this,它们代表什么? 最佳答

javascript - window.location 和 window.location.href 有区别吗?

这个问题在这里已经有了答案:关闭11年前。PossibleDuplicate:Javascript:Settingwindow.location.hrefversuswindow.location当我在浏览器中测试这些代码时,它们似乎是一样的。有区别吗?1window.location="http://stackoverflow.com";2window.location.href="http://stackoverflow.com";