获取的indexOf JavaScript数组由JavaScript对象 [英] Getting indexOf Javascript array made up of Javascript Objects

查看:142
本文介绍了获取的indexOf JavaScript数组由JavaScript对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让这个的indexOf阵列上?

  myarray的无功=新阵列(
    {标题:测试1,ID:头1,HTML:头1,作风:背景色:红色;颜色:白色;});


解决方案

这是我做过什么,使其工作 - 但它不是pretty:

  //检查,看看是否我们要卡,应该是右边或左边。
VAR rightOrLeft =左;
变种destinationIndex = 0;
对于(VAR I = 0; I<动态preezeArray.length;我++){
        如果(动态preezeArray [I] .ID == this.text){
                  destinationIndex = I;
       };
}如果(destinationIndex< currentCarouselIndex){
         rightOrLeft =权利;
}preezer.setActiveItem(this.text,{类型:'滑',方向:rightOrLeft});
currentCarouselIndex = preezer.getActiveIndex();

这一切只是点击按钮时,让我的煎茶传送带的样子吧,但现在我意识到,如果有人手动,它不会设置currentCarouselIndex幻灯片吧...的Bleh,这是很多工作只是为了使它看起来好一点。

Is there a way to get indexOf on this array?

var myArray = new Array(
    {title: "Test1", id: "Header1", html: "Header1", style: "background-color: red; color: white;"});

解决方案

This is what I did to make it work -- but it's not pretty:

//Check to see if we are going to a card that should be right or left.
var rightOrLeft = "left";
var destinationIndex = 0;
for(var i=0; i < dynamicPreezeArray.length; i++){
        if (dynamicPreezeArray[i].id == this.text) {
                  destinationIndex = i;
       };
}

if (destinationIndex < currentCarouselIndex) {
         rightOrLeft = "right";
}

preezer.setActiveItem(this.text,{type:'slide',direction: rightOrLeft});
currentCarouselIndex = preezer.getActiveIndex();   

This was all just to make my Sencha carousel look right when clicking buttons, but now I realize that if someone slides it manually that it wont set the currentCarouselIndex... bleh, this is a lot of work just to make it look a little better.

这篇关于获取的indexOf JavaScript数组由JavaScript对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆