因此,我能够以正确的方式获取音节,但以某种方式无法获取word
,但事实是:我正在以与我完全相同的方式获取word
我的音节正在做。
function getExerciseBlock(i, data) {
var eBlock = $('<div/>',{
'id': i,
'class': 'col-md-6 eBlock well'
});
data = data || {
word: '',
syllables: ['','','','']
};
$(eBlock).append(
getRemoveBtnExercise(i),
getAudioBtn(i),
getWordInput(i, data.word),
getWordPartInput(i, data.syllables[0]),
getWordPartInput(i, data.syllables[1]),
getWordPartInput(i, data.syllables[2]),
getWordPartInput(i, data.syllables[3])
);
return eBlock;
}
将其取回的“循环”:
// Below this comment starts the fetching data back, so the moderator can change data
$(document).ready(function () {
$.getJSON('json_files/jsonData_' + ID + '.json', function(json) {
// Loops through the words and fetches them back to the CMS side.
var exercise = json.main_object.main_object.exercises;
exercise.forEach((exercise, index) => {
$('#my_form').append(getExerciseBlock(index, exercise));
console.log(exercise);
});
});
});
我的JSON如下所示:
{
"main_object": {
"id": "new",
"getExerciseTitle": "Example",
"language": "nl_NL",
"application": "lettergrepen",
"main_object": {
"title": "Example",
"language": "nl_NL",
"exercises": [{
"word": "Example",
"syllables": [
"Example1",
"Example2",
"",
""
]
}
]
},
"dataType": "json"
}
}
编辑:有人要求我提供以下功能:
getWordInput是word
应该到达的函数(从JSON取回时)
function getWordInput(id, cValue) {
cValue = cValue || '';
var wInput = $('<input/>', {
'class': 'exerciseGetWordInput_' + id + ' form-group form-control ExerciseGetWordInput word',
'type': 'text',
'name': 'question_takeAudio_exerciseWord['+ exerciseAudioInput +']',
'placeholder': 'Exercise',
'id': 'exerciseGetWordInput',
'required': true
});
return wInput;
}
getWordPartInput =用于工作的JSON文件中的音节。
// This is the function that creates the syllable inputs.
function getWordPartInput(id, cValue){
cValue = cValue || '';
var wpInput = $('<input/>', {
'class': 'form-group form-control syllable syl ' + TT ++,
'type': 'text',
'value': cValue,
'placeholder': 'Syllables',
'name': 'Syllablescounter['+ SyllablesID++ +']'
});
return wpInput;
}
需要一些代码,但对我来说却毫无用处:
function getAudioBtn(id, cValue){
cValue = cValue || '';
var audioBtn = $('<a/>', {
'class': 'sound btn btn-primary'
}).html('<i class="fa fa-volume-up"></i>');
return audioBtn;
}
function getRemoveBtnExercise(target, i){
var RemoveExerciseBtn = $('<a/>', {
'class': 'btn btn-danger'
}).on('click', function(){
console.log($('.eblock').prop('id'))
$('#' + target).remove();
}).html('<i class="fa fa-close"></i>');
return RemoveExerciseBtn;
}
下面的这段代码是一个添加按钮,单击该按钮可创建具有所有功能的eBlock
。例如,当主持人想要创建一个全新的练习时,将使用此按钮。
$(document).ready(function() {
var id = 0;
var addOpdracht = $('<a/>', {
'class': 'btn btn-success',
'id': 'addOpdracht'
}).on('click', function() {
$('#my_form').append(getExerciseBlock(id));
$(".exerciseGetWordInput_" + id).focus().select();
id++;
exerciseAudioInput++;
}).html('<i class="fa fa-plus fa-2x"></i>');
$('#my_form').append(addOpdracht);
$('#my_form').append(getExerciseTitle());
});
答案 0 :(得分:1)
您只是在'value': cValue,
函数中缺少getWordInput()
。修改如下:
function getWordInput(id, cValue) {
cValue = cValue || '';
var wInput = $('<input/>', {
'class': 'exerciseGetWordInput_' + id + ' form-group form-control ExerciseGetWordInput word',
'type': 'text',
'value': cValue,
'name': 'question_takeAudio_exerciseWord['+ exerciseAudioInput +']',
'placeholder': 'Exercise',
'id': 'exerciseGetWordInput',
'required': true
});
return wInput;
}