一区在线电影,国产在线首页,中文字幕精,天天爽天天射,夜色99,日韩国产成人av,伊人久久综合视频

威勢網(wǎng)絡(luò),為您的企業(yè)和團隊注入互聯(lián)網(wǎng)活力!
服務(wù)熱線:138-9741-0341

js 對象、數(shù)組的定義,及數(shù)組元素查找是否包含子項

發(fā)布日期:2022/10/11 作者: 瀏覽:657
            var AllowedGrantTypes = []; //在循環(huán)體外面定義一個全局?jǐn)?shù)組對象,等一下往這里面PUSH進(jìn)內(nèi)容
.... 省略若干行

	            onSelect: function(record){

                    var GrantType={};  //定義一個子項,要push進(jìn)數(shù)組中
                    GrantType.name=record.name;  //添加字段
                    GrantType.id=record.id;  //添加字段
                    console.log("+=:"+record.name + record.id); 
                    //if (AllowedGrantTypes.indexOf(GrantType) < 0) {   //這樣子查找是沒有結(jié)果的,就結(jié)果存在也會返回-1
                    //    AllowedGrantTypes.push(GrantType);
                    //}
                    if (AllowedGrantTypes.findIndex(item=>item.id==GrantType.id && item.name==GrantType.name) < 0) {  //用這種方法去查找比較保險,若不存在,則push
                        AllowedGrantTypes.push(GrantType);
                    }
                    
                    console.log("length=:"+AllowedGrantTypes.length); 
                },

aa

如上圖所示,AllowedGrantTypes中明明存在granttype項,但是返回FALSE。


下拉加載更多評論
最新評論
暫無!