草庐IT

this-page

全部标签

javascript - React TypeError this._test 不是一个函数

由于我是JavaScript和React的新手,我真的很难找出正确的语法。这是我的问题:_handleDrop(files)应该调用函数_validateXML(txt)但实际上没有。我收到此错误UncaughtTypeError:this._validateXMLisnotafunction并且无法弄清楚原因。回调_handleDrop(files)工作正常。当我尝试这种语法_validateXML:function(txt)时,我在编译时立即收到错误消息。是因为ecmascript吗?importReactfrom'react';import'./UploadXML.scss';i

javascript - 在 JavaScript 事件回调中绑定(bind) "this"的正确方法?

我创建了一个名为SearchBox的类来处理搜索交互(延迟触发、按回车键搜索、在搜索处于事件状态时阻止搜索、在搜索完成和文本更改时同步结果等)。所有类方法都是原型(prototype)方法,意味着可以通过this访问。在下面的代码中,假设p是类的原型(prototype)。p.registerListeners=function(){$(this.element).on('keypress',this.searchKeyPressed);};p.unregisterListeners=function(){$(this.element).off('keypress',this.sear

javascript - 如何使用(this)访问Angular 2 http rxjs catch函数中的对象属性

在Angular2中使用新的http服务,我想对我的错误做更多的事情,而不仅仅是在控制台中抛出错误。不幸的是,我似乎无法从catch回调函数中访问我的对象属性。我的http服务调用:returnthis.http.get(this.apiUrl,options).map(this.extractData,this).catch(this.handleError)我的handleError回调fn:handleError(error){console.log(this)//undefined!if(error.status===401){this.router.navigate(['/l

javascript - React Native 中的定时器 (this.setTimeout)

我正在尝试在我的组件中设置一个TimeOut函数。据我了解,仅仅像在网络上那样使用setTimeout并不是一个正确的答案。这会导致时序和内存泄漏问题。我读到有一个现有的TimersAPI在nativereact中。但是,它不符合ES6,我引用:KeepinmindthatifyouuseES6classesforyourReactcomponentsthereisnobuilt-inAPIformixins.TouseTimerMixinwithES6classes,werecommendreact-mixin.然后react-mixin,我们发现这条消息:Note:mixinsar

javascript - VideoJS : Stopping video on modal close and not embedding in page

我一直在使用JavaScript脚本VideoJS:http://videojs.com/构建一些可以在弹出窗口中显示给用户的视频播放器。我按如下方式构建了弹出窗口:VideoJS.setupAllWhenReady();jQuery(document).ready(function(){//videoshavevideojsappliedtothem//$("video").VideoJS()$(".show-video").click(function(){$(".video-background").show();$(".video-container").fadeIn("fas

javascript - 找不到变量 : page in PhantomJS

我是测试初学者,无论是单元测试还是UI测试我正在尝试使用以下代码为我的登录页面创建一个UI测试:console.log("TestedeLogin");varpage=require('webpage').create();page.open('http://localhost/login',function(status){console.log("Pageloadeed");if(status==="success"){page.render('example1.png');}page.evaluate(function(){//$("#numeroUsuario").val("9

javascript - 警告 - 全局 this 对象的危险使用

在GoogleClosureCompiler中我收到警告WARNING-dangeroususeoftheglobalthisobject这是一个例子。错误行和偏移量指的是单词this的开头functionaToggle(){if(shown)toggle.show()elsetoggle.hide()$(this).text(shown?'Clicktohide':'Clicktoshow')shown=!shown}link.onclick=aToggle我只想将其更改为匿名方法,但我在文件的其他地方重新使用了aToggle,因此需要对其进行命名。我可以将aToggle标记为/**

javascript - 我们可以将 $(this) 与其他选择器一起使用吗?

例如:$("#"+$(this).attr("id")+"option[value='0']")我们能否将代码简化为类似的东西$(this+"option[value='0']") 最佳答案 这些将与您的第一个语句执行相同的操作:找到具有0作为它们的value的option元素并且是(不限制直接)this的child。$(this).find('option[value="0"]')或$('option[value="0"]',this)资源:jQuery.find()UnderstandingcontextinjQueryjsFi

javascript - Javascript 对象中的 var 与 this

我正在为node.js开发一个网络框架。这是代码;functionRouter(request,response){this.routes={};varparse=require('url').parse;varpath=parse(request.url).pathname,reqRoutes=this.routes[request.method],reqRoutesLen=reqRoutes.length;.....//morecode};我应该把所有的var都改成这个吗,像这样:functionRouter(request,response){this.routes={};thi

javascript - 匿名函数中的 "this"?

在JohnResig的书“ProJavascripttechniques”中,他描述了一种使用以下代码生成动态对象方法的方法://CreateanewuserobjectthatacceptsanobjectofpropertiesfunctionUser(properties){//Iteratethroughthepropertiesoftheobject,andmakesure//thatit'sproperlyscoped(asdiscussedpreviously)for(variinproperties){(function(){//Createanewgetterfort