通过单击数组元素无法找到正确的indexOf值

时间:2018-07-19 20:27:51

标签: javascript angularjs

我的html和js代码如下:

html

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.payne.simpletestapp"
        minSdkVersion 16
        targetSdkVersion 27
        multiDexEnabled true
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:support-vector-drawable:27.1.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    api 'com.google.firebase:firebase-auth:16.0.2'
    implementation 'com.firebaseui:firebase-ui-auth:4.1.0'
    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.android.gms:play-services-auth:15.0.1'
    implementation 'com.google.firebase:firebase-admin:6.3.0'

    implementation 'org.osmdroid:osmdroid-android:6.0.1'
    implementation 'org.osmdroid:osmdroid-wms:6.0.1'
    implementation 'org.osmdroid:osmdroid-mapsforge:6.0.1'
    implementation 'org.osmdroid:osmdroid-geopackage:6.0.1'
    api 'com.github.MKergall:osmbonuspack:6.5.1'


    implementation 'org.springframework.android:spring-android-rest-template:2.0.0.M3'
    api 'org.apache.httpcomponents:httpclient-android:4.3.5'

    implementation 'com.squareup.picasso:picasso:2.71828'

    // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind
    implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.6'


}

repositories {
    maven {
        url 'https://repo.spring.io/libs-milestone'
    }
}

apply plugin: 'com.google.gms.google-services'

js

<img ng-repeat = "x in images" ng-src = "{{x.url}}" ng-click = "mag(x)">

$scope.images = [img1, img2, img3, img4] var l; $scope.mag = function(x){ l = $scope.images.indexOf(x); console.log("value of l "+l); } 是存在漏洞的伪对象。

当我在img1, img2...上单击时,在first image中显示console.log()的{​​{1}},但单击value of l is 0图像时,值为{{1} },点击correct的{​​{1}}图像值,然后点击2nd的{​​{1}}图像值。

2 个答案:

答案 0 :(得分:0)

如果仅需要元素的索引,则可以使用sudo aa-complain libvirt-<uuid> //replace <uuid> with uuid of vm

引用https://docs.angularjs.org/api/ng/directive/ngRepeat

示例:

$index

<img ng-repeat = "x in images" ng-src = "{{x.url}}" ng-click = "mag($index)">

答案 1 :(得分:0)

您可以做到

<body ng-app="myApp" ng-controller="myCtrl">

    <h1 ng-repeat="x in records">{{x}}</h1>

    <script>
        var app = angular.module("myApp", []);
        app.controller("myCtrl", function($scope) {
            $scope.images = [img1, img2, img3, img4]
            var l;
            $scope.mag = function(x){
            l = $scope.images.indexOf(x);
            console.log("value of l "+l);
          };
    });
    </script>

</body>