草庐IT

names_with_underscores

全部标签

javascript - Select2.js v4.0 : how set the default selected value with a local array data source?

通过使用select2.jsv4插件,当我使用本地数组数据作为源时,如何设置默认选择值?以这段代码为例vardata_names=[{id:0,text:"Henri",},{id:1,text:"John",},{id:2,text:"Victor",},{id:3,text:"Marie",}];$('select').select2({data:data_names,});如何设置id3为默认选中值? 最佳答案 $('.select').select2({data:data_names,}).select2("val",3);

javascript - 在 jquery 对象集合上使用 underscore.js 列表函数

我正在使用一个同时使用jQuery和underscore.js的应用程序。我希望能够在jQuery对象集合上使用一些下划线的迭代器函数,例如any()和all()。有没有办法做到这一点?我想做类似于以下的事情:checkboxes=$("input[type=checkbox]");_.filter(checkboxes,function(box){returnbox.is(":checked");});但这会引发错误:UncaughtTypeError:Object#hasnomethod'is'所以我假设box在这个上下文中的行为不像jQuery对象。

javascript - this.name 在 javascript 中返回 undefined

我正在尝试远程创建一个onclick对于每个(以节省打字时间)。这是window.onload()功能:window.onload=function(){divel=document.getElementsByTagName('div');for(varelindivel){divel[el].onmouseover=function(){this.style.textDecoration="underline";};divel[el].onmouseout=function(){this.style.textDecoration="none";};divel[el].onclick=

javascript - 学习 JavaScript : display all firstnames with B as first letter

我是第一次学习JavaScript,我想知道为什么我的代码不起作用。我有Python/Django知识。目标:我必须创建一个姓名列表,并且我必须只显示以“B”字母开头的名字。我的脚本:varlistNames=['Paul','Bruno','Arthur','Bert','José']for(variinlistNames){if(i.substr(0,1)==='B'){console.log(i);}}但是这段代码没有显示任何东西。 最佳答案 您需要使用listNames[i]作为i为您提供数组listNames的index。

javascript - 使用 Underscore 的 _.debounce() 方法

我正在尝试使用UnderscoreJS和它的_.debounce()方法来停止在keyup事件上重复触发的回调函数。我这样做是因为每次您开始输入时,都会启动AJAX调用,因此为您输入的每个字符进行调用会非常昂贵(:这就是我使用方法的方式:onTypeEvents:function(selector,callback){return$(selector).on('keyup',function(event){varthat=$(this).val().trim();switch(event.keyCode){case8:if(that!==''){if(that.length>=2){r

javascript - 前端 : underscore. js 或 async.js 通过 browserify?

因此,如果您是后端node.js开发人员,您就会知道名为async的很棒的库。.如果您是前端开发人员,您会知道名为underscore的很棒的库。.现在的情况是,这两个库在某种程度上倾向于提供相似的功能。所以问题是,使用browserify在前端使用异步是否有意义?? 最佳答案 Underscore是一个实用程序库,它提供了一些有用的函数,例如each、map和reduce。但是,所有这些都是同步工作的。例如varresults=_.map([1,2,3],function(value,index,list){returnvalue

javascript - rect with stroke,笔划线在缩放时会被错误转换

我从这个网站和这里的贡献者那里得到了很多帮助,谢谢。现在我有一个关于Fabric.js中带有笔划的矩形的问题,因为我将它用作图像和文本的占位符,当我缩放它时,边框线宽度也被缩放,我认为这是我想要的问题保持边框宽度不变。varcanvas=newfabric.Canvas("c1");varel=newfabric.Rect({originX:"left",originY:"top",left:5,top:5,stroke:"#ccc",strokWidth:1,fill:'transparent',opacity:1,width:200,height:200,cornerSize:6}

javascript - 未捕获的语法错误 : Unexpected token instanceof (with Chrome Javascript console)

我很惊讶在Chromejs控制台输入如下代码:{}instanceofObject导致此错误消息:UncaughtSyntaxError:Unexpectedtokeninstanceof谁能告诉我这是为什么以及如何解决它? 最佳答案 instanceof的语法是:RelationalExpressioninstanceofShiftExpression根据ECMA-262§11.8.语句开头的标点符号{被视为block的开始,因此以下}关闭block并结束语句。后面的instanceof运算符是下一条语句的开始,但它不能在开始处,

javascript - Spring stomp websockets with vue.js

我正在尝试将Springwebsockets(STOMP)与Vue结合使用,但不知道该怎么做,甚至不知道该怎么做。我的websockets使用纯JS,但是当我尝试使用Vue时,我卡住了。这是我的Vue代码:varapp=newVue({el:'#app',data:{stompClient:null,gold:0},methods:{sendEvent:function(){this.stompClient.send("/app/hello",{},JSON.stringify({'name':$("#name").val()}));}},created:function(){this

javascript - [Vue 警告] : Error in render function: "TypeError: Cannot read property ' first_name' of null"

我有以下Navigation.vue组件:{{user.first_name}}import{mapActions,mapGetters}from'vuex'exportdefault{name:'hello',methods:{...mapActions(['myAccount'])},mounted:function(){if(localStorage.getItem('access_token')){this.myAccount()}},computed:{...mapGetters(['user'])}}此代码返回:[Vuewarn]:Errorinrenderfunction