草庐IT

CALL_STATE_IDLE

全部标签

javascript - UI-路由器 : param values not valid for state

githubrepo对于这个问题。我完全没有希望了。我创建了一个angular1.5.8应用程序,它在屏幕上显示Node。有两种类型的Node-文件夹和图片。当点击图片Node时,它应该使用ui-router传递params,我按照ui-router文档说的做.{{picture.url}}的插值和其他一切工作正常并提供正确的文件路径。奇怪的是,当我手动执行时,请转到:/picture/url它传递文件的路径。我得到的错误是:Paramvaluesnotvalidforstate'picture'app.config(function($stateProvider,$urlRouteP

javascript - 为什么使用 .call(this) 而不是括号

这个问题在这里已经有了答案:Reasonbehindthisselfinvokinganonymousfunctionvariant(5个答案)关闭8年前。有没有什么特别的原因让我经常遇到:(function(){console.log("Hello");}).call(this);代替:(function(){console.log("Hello");})();传不传this调用应该是一样的效果吧?似乎有一些性能差异:http://jsperf.com/call-vs-parenthesis.

javascript - 为什么不能使用 .call() 调用 console.log

下面的代码返回一个带有“hello”的弹出窗口。alert.call(this,'hello');但是下面的代码返回错误“TypeError:Illegalinvocation”。console.log.call(this,'hello');alert和console.log的实现有什么区别? 最佳答案 alert是一个全局方法(window.alert)。如果你调用它alert.call(this),this就是窗口对象。因为log是console对象中的一个方法,它期望this是console对象本身,但是你还是用this(wi

javascript - 如果在 angularJS 的配置中配置,则测试 stateProvider 状态在 $state 上返回 null

我有这样一个配置:angular.module('myModule',['ui.router']).config(['$stateProvider',function($stateProvider){$stateProvider.state('app.home',{abstract:true,url:'/home',template:'FooBar'});}]);和像这样使用jasmine的单元测试:'usestrict';describe('Module:myModule',function(){var$rootScope,$state;beforeEach(module('ui.r

javascript - 如何用参数做 $state.go() ?

我已经完美地初始化了$stateProvider并且我正在将所有这些状态与ui-sref一起使用。效果很好。用户按下按钮并通过$stateProvider进入编辑页面。在这个页面上,我有一个执行$http请求的表单:this.pushData=function(data){$http.post('/data/'+$stateParams.dataId+'/otherdata',JSON.stringify({id:otherdata.id,name:otherdata.name}),configAuth).then(functionsuccess(response){varaddedD

javascript - 在 IIFE 上使用 .call(this)

我见过用.call(this)包裹的IIFE,而不仅仅是()。为什么要这样做?上下文:https://github.com/dmauro/Keypress/blob/development/keypress.js(据我了解,this将引用window对象-无论如何都会调用IIFE。这似乎是多余的。) 最佳答案 如果不使用call调用IIFE,它里面的this会引用全局对象window(或者undefined在严格模式下)。使用.call(this)将传递给它任何this在调用时引用的内容(无论当前上下文是什么)。例如,您想使用.ca

javascript - 未捕获的类型错误 : Cannot call method 'replace' of undefined underscore. js

我是backbone.js和underscore.js的新手。HTML:我调用View文件的地方:JS函数(与javascript项目配合良好):functionCart(){......this.showCart=function(){varitem=deserializeJSONToObj(window.localStorage.getItem(Cart.storageName));varstr='';str+='ItemtobuyQuantity';$.each(item,function(i,item){str+=''+trimString(item.Name,50)+'Ava

javascript - 为什么使用 Function.prototype.bind 而不是 Function.prototype.call?

myFunction.call(thisArg,arg1,arg2...)我的理解是,当我使用call方法并提供thisArg时,函数中的this值设置为我传入的对象.myFunction.bind(thisArg,arg1,arg2...)而另一方面,bind方法返回一个新函数,新函数的this上下文设置为我传入的对象。但我不明白的是为什么要使用bind而不是call。如果我只想更改this的上下文,call对我来说就足够了。那为什么要在IE8及以下浏览器中中断时使用bind。那么,与call相比,什么时候使用bind会更好? 最佳答案

javascript - Angular $state.go {重新加载 : true} shouldn't reinitialize the abstract parent controller

我正在使用ui-route进行导航。我的父状态称为ma​​in,它是一个abstract状态(url:/main)和子状态products和用户(网址:/main/products和/main/users)。app.config(["$stateProvider","$urlRouterProvider",function($stateProvider,$urlRouterProvider){$urlRouterProvider.otherwise("/main/products");$stateProvider.state("main",{url:"/main",templateUr

javascript - 在 JavaScript 中使用 call() 或 apply() 返回值

有没有办法在调用call()或apply()时获取函数的返回值?我的场景:我有一个函数可以与apply()函数配合使用。在对象构造函数上:varsomeObject=newSomeObject({NameFunction:"MakeNames"});在对象方法的循环中:varname="";for(vari=0;iMakeNames函数:functionMakeNames(data){returndata.FirstName+""+data.LastName;}那个varname保持为空,因为apply没有从函数返回任何值。请注意,我确信该函数已被调用并且参数已成功传递。请不要告诉我直