我似乎无法遍历syllables
,而我对word
做的事情却完全相同。但是,这行得通,怎么办?
我的JSON:
{
"main_object": {
"id": "new",
"getExerciseTitle": "Example",
"language": "nl_NL",
"application": "lettergrepen",
"main_object": {
"title": "Example",
"language": "nl_NL",
"exercises": [
{
"word": "espresso",
"syllables": [
"es",
"presso",
"",
""
]
}
]
},
"dataType": "json"
}
}
我的syllables
循环:
var exerSyll = json.main_object.main_object.exercises;
$.map(exerSyll, function(exerSyll, s) {
$(".syllable" + s).val(exercise.syllables)
});
我的word
循环确实有效:
var exercise = json.main_object.main_object.exercises;
$.map(exercise, function(exercise, i) {
$("#addOpdracht").click();
$(".exerciseGetWordInput_" + i).val(exercise.word)
});
应该在其中附加syllables
的地方:
function getWordPartInput(id, cValue){
cValue = cValue || '';
var wpInput = $('<input/>', {
'class': 'form-group form-control syllable',
'type': 'text',
'value': cValue,
'placeholder': 'Syllables',
'name': 'Syllablescounter['+ SyllablesID++ +']'
});
return wpInput;
}