我确信这将是我缺少的东西或者其他东西,但是现在我无法找到我做错了什么,你能不能帮我找到为什么“Wordmeanings”没有正确地指出其正确的含义?我的意思是:
但我担心的不是那样......因为正如你在笔中看到的那样,每个单词都显示出不是所希望的含义......当然它的某些东西我做错了读数组但是可以'找到错误¿coul du help me?
这是笔:https://codepen.io/stsanchez/pen/WZqwpN?editors=0010#0
$.getJSON( "https://raw.githubusercontent.com/staranco/smarted/master/js/dictionary.json", function(data) {
var dictionary = data.dictionary;
var d;
for(d = 0; d < dictionary.length; d ++) {
var letters = dictionary[d];
var letterSectionId = (Object.keys(letters)).toString();
var letterSection = $('<section/>', {
'class': 'results__letter',
'id': 'section_letter-' + letterSectionId
}).appendTo('.results__container');
$.each(letters, function(i, item) {
var words = Object.values(letters[i]);
var w;
for(w = 0; w < words.length; w ++) {
var word = Object.values(words[w])[0];
var wordName = Object.values(word[0]).toString();
var wordEtymology = Object.values(word[1]).toString();
//To do: show word meanings
var wordMeanings = Object.values(word[2]);
$.each(wordMeanings, function(j, item) {
$('<ul/>', {
'class': 'article__definitions',
html: ('<li class="article__definition">' + wordMeanings[j] + '</li>')
}).appendTo('.results__article')
});
var wordArticle = $('<article/>', {
'class': 'results__article',
'data-letter': letterSectionId,
html: ('<header class="article__header">' + wordName + '</header><p class="article__specs">' + wordEtymology + '</p>')
}).appendTo('.results__letter#section_letter-' + letterSectionId);
}
})}}).done(function() {}).fail(function() {}).always(function() {})
这是JSON https://raw.githubusercontent.com/staranco/smarted/master/js/dictionary.json
答案 0 :(得分:0)
试一试。希望这项工作符合您的预期
$(function(){
$.getJSON( "https://raw.githubusercontent.com/staranco/smarted/master/js/dictionary.json", function(data) {
var dictionary = data.dictionary;
var d;
for(d = 0; d < dictionary.length; d ++) {
var letters = dictionary[d];
var letterSectionId = (Object.keys(letters)).toString();
var letterSection = $('<section/>', {
'class': 'results__letter',
'id': 'section_letter-' + letterSectionId
}).appendTo('.results__container');
$.each(letters, function(i, item) {
var words = Object.values(letters[i]);
var w;
for(w = 0; w < words.length; w ++) {
var word = Object.values(words[w])[0];
var wordName = Object.values(word[0]).toString();
var wordEtymology = Object.values(word[1]).toString();
//To do: show word meanings
var wordMeanings = Object.values(word[2]);
var wordArticle = $('<article/>', {
'class': 'results__article',
'data-letter': letterSectionId,
html: ('<header class="article__header">' + wordName + '</header><p class="article__specs">' + wordEtymology + '</p>')
}).appendTo('.results__letter#section_letter-' + letterSectionId);
$.each(wordMeanings, function(j, items) {
var html='';
$.each(items, function(k, item){
html = html + '<li class="article__definition">' + item + '</li>';
});
$('<ul/>', {
'class': 'article__definitions',
html: (html)
}).appendTo('.results__letter#section_letter-' + letterSectionId +' .results__article')
});
}
})
}
}).done(function() {}).fail(function() {}).always(function() {});
});
同时观察我在您的代码中所做的更改,以了解错误。
我在追加单词Article后移动了下面的代码。并且还将.appendTo('.results__article')
更改为.appendTo('.results__letter#section_letter-' + letterSectionId +' .results__article')
,因为只有附加到类才会附加到具有相同类的所有div。
$.each(wordMeanings, function(j, item) {
$('<ul/>', {
'class': 'article__definitions',
html: ('<li class="article__definition">' + wordMeanings[j] + '</li>')
}).appendTo('.results__letter#section_letter-' + letterSectionId +' .results__article')
});