JSON数据与track的使用不匹配,如

时间:2015-10-22 11:44:16

标签: javascript json angularjs

我有三个相互连接的选择菜单。

- 第一个显示:系列名称

- 第二个显示:属于第一个选择菜单中的系列的章节编号。

- 第三个显示:属于第二个选择菜单中章节的页码。

现在我想要的是根据$scope.data设置第一和第二选择菜单的选定值。在我的控制器中,我设法设置第一个但第二个因为JSON数据不匹配而无效。如果我使用track by它的工作,但这次我不能使用as。我该如何解决这个问题?

<select ng-model="selManga" ng-options="manga.seri for manga in mangalar track by manga.seri"> 
<option value="">Manga</option> 
</select>
<select ng-change="selPage = 0" ng-model="selChapter" ng-options="selManga.randomword.indexOf(chapter) as chapter.klasor for chapter in selManga.randomword"> 
<option value="">Chapter</option> 
</select>
 <select ng-model="selPage" ng-options="selManga.randomword[selChapter].yol.indexOf(page) as selManga.randomword[selChapter].yol.indexOf(page) + 1 for page in selManga.randomword[selChapter].yol">
</select>
<img ng-src="{{selManga.randomword[selChapter].yol[selPage]}}" ng-click="next(selManga, selChapter, selPage)"> 

使用Javascript:

$scope.mangalar = loHemen; //JSON Data
$scope.selManga = miloMangaInArray; // First select menu's ng-model and its working.
$scope.selChapter = $scope.selManga.randomword[a]; //Second select menu's ng-model and its not working due to no matching JSON data.

JSON数据:

[{"seri": "Naruto",
  "randomword": [{
        "klasor": "138",
        "yol": [path/to/images
    ]
},
{
        "klasor": "300",
        "yol": [path/to/images

    ]
}
]
},
{
 "seri": "One Piece",
 "randomword": [
{
        "klasor": "137",
        "yol": [path/to/images

    ]
}
]
}
])

enter image description here

1 个答案:

答案 0 :(得分:0)

您的Json数据无效;

有效的例子是:

[{"seri":"Naruto","randomword":[{"klasor":"138","yol":["a","b","c"]},{"klasor":"300","yol":["a","b","c"]}]},{"seri":"Naruto","randomword":[{"klasor":"139","yol":["a","b","c"]},{"klasor":"301","yol":["a","b","c"]}]}]