Commit 9e994b29 authored by limingzhe's avatar limingzhe

fix: debug

parent 3d5c914f
...@@ -67,7 +67,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy { ...@@ -67,7 +67,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
ngOnInit() { ngOnInit() {
this.getBookTextLis(); this.getBookTextList();
...@@ -108,9 +108,9 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy { ...@@ -108,9 +108,9 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
const ques = this.item.quesArr[0]; const ques = this.item.quesArr[0];
this.randomSentenceList = this.getRandomList(this.bookTextList); this.randomSentenceList = this.getRandomList(this.bookTextList);
if (this.randomSentenceList.length > 10) { // if (this.randomSentenceList.length > 10) {
this.randomSentenceList.length = 10; // this.randomSentenceList.length = 10;
} // }
console.log('this.randomSentenceList : ' + this.randomSentenceList ); console.log('this.randomSentenceList : ' + this.randomSentenceList );
...@@ -125,6 +125,24 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy { ...@@ -125,6 +125,24 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
this.save(); this.save();
} }
filterDuplicateText(arr: any[]): any[] {
// 使用 Map 来记录已经出现过的 text
const textMap = new Map();
// 使用 filter 过滤数组
return arr.filter(item => {
// 如果这个 text 还没有出现过,就把它加入 Map 并保留这个元素
if (!textMap.has(item.text)) {
textMap.set(item.text, true);
return true;
}
// 如果这个 text 已经出现过,就过滤掉这个元素
return false;
});
}
init() { init() {
if (!this.item.quesArr) { if (!this.item.quesArr) {
...@@ -406,201 +424,204 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy { ...@@ -406,201 +424,204 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
}, 1); }, 1);
} }
getBookTextLis() { getBookTextList() {
let resData1 = { // let resData1 = {
"msg": "success", // "msg": "success",
"data": [ // "data": [
{ // {
"number": 4, // "number": 4,
"text": "Hank Hammer" // "text": "Hank Hammer"
}, // },
{ // {
"number": 5, // "number": 5,
"text": "MEET THE TOOL TEAM" // "text": "MEET THE TOOL TEAM"
}, // },
{ // {
"number": 5, // "number": 5,
"text": "Tia Tape Measure" // "text": "Tia Tape Measure"
}, // },
{ // {
"number": 5, // "number": 5,
"text": "Hank Hammer" // "text": "Hank Hammer"
}, // },
{ // {
"number": 6, // "number": 6,
"text": "Sammy Saw" // "text": "Sammy Saw"
}, // },
{ // {
"number": 6, // "number": 6,
"text": "Sophie Screwdriver" // "text": "Sophie Screwdriver"
}, // },
{ // {
"number": 7, // "number": 7,
"text": "Today is the big contest. Hank is very excited! He jumps out of bed." // "text": "Today is the big contest. Hank is very excited! He jumps out of bed."
}, // },
{ // {
"number": 8, // "number": 8,
"text": "He brushes his teeth and gets ready." // "text": "He brushes his teeth and gets ready."
}, // },
{ // {
"number": 9, // "number": 9,
"text": "\"Have a fun day,\" his mom says." // "text": "\"Have a fun day,\" his mom says."
}, // },
{ // {
"number": 9, // "number": 9,
"text": "“Good luck at the contest.\"" // "text": "“Good luck at the contest.\""
}, // },
{ // {
"number": 10, // "number": 10,
"text": "\"Thanks, Mom,\" Hank says as he rushes out the door." // "text": "\"Thanks, Mom,\" Hank says as he rushes out the door."
}, // },
{ // {
"number": 11, // "number": 11,
"text": "\"Hi, everyone! Are you ready for the big contest?\" asks Hank." // "text": "\"Hi, everyone! Are you ready for the big contest?\" asks Hank."
}, // },
{ // {
"number": 12, // "number": 12,
"text": "\"We're ready!\" they yell." // "text": "\"We're ready!\" they yell."
}, // },
{ // {
"number": 13, // "number": 13,
"text": "\"I have the wood,\" says Sammy." // "text": "\"I have the wood,\" says Sammy."
}, // },
{ // {
"number": 13, // "number": 13,
"text": "\"I have the nails,\" says Tia." // "text": "\"I have the nails,\" says Tia."
}, // },
{ // {
"number": 14, // "number": 14,
"text": "“I have the red paint and the blue paint,\"says Sophie." // "text": "“I have the red paint and the blue paint,\"says Sophie."
}, // },
{ // {
"number": 15, // "number": 15,
"text": "“And I have the plans,\" says Hank." // "text": "“And I have the plans,\" says Hank."
}, // },
{ // {
"number": 16, // "number": 16,
"text": "“We are going to build the best birdhouse!\"says Sammy." // "text": "“We are going to build the best birdhouse!\"says Sammy."
}, // },
{ // {
"number": 17, // "number": 17,
"text": "\"It's time to start,\"says Sophie." // "text": "\"It's time to start,\"says Sophie."
}, // },
{ // {
"number": 17, // "number": 17,
"text": "\"What do we do?\" asks Tia." // "text": "\"What do we do?\" asks Tia."
}, // },
{ // {
"number": 18, // "number": 18,
"text": "“Just follow my plan,\" says Hank." // "text": "“Just follow my plan,\" says Hank."
}, // },
{ // {
"number": 18, // "number": 18,
"text": "“I have everything mapped out right here.\"" // "text": "“I have everything mapped out right here.\""
}, // },
{ // {
"number": 19, // "number": 19,
"text": "“First, we measure everything,\"" // "text": "“First, we measure everything,\""
}, // },
{ // {
"number": 19, // "number": 19,
"text": "says Hank." // "text": "says Hank."
}, // },
{ // {
"number": 20, // "number": 20,
"text": "\"That's my job,\" says Tia." // "text": "\"That's my job,\" says Tia."
}, // },
{ // {
"number": 20, // "number": 20,
"text": "“Great!\"says Hank." // "text": "“Great!\"says Hank."
}, // },
{ // {
"number": 21, // "number": 21,
"text": "\"Next, we cut the wood,\"" // "text": "\"Next, we cut the wood,\""
}, // },
{ // {
"number": 21, // "number": 21,
"text": "says Hank." // "text": "says Hank."
}, // },
{ // {
"number": 22, // "number": 22,
"text": "\"That's my job,\" says Sammy." // "text": "\"That's my job,\" says Sammy."
}, // },
{ // {
"number": 22, // "number": 22,
"text": "\"Great!\" says Hank." // "text": "\"Great!\" says Hank."
}, // },
{ // {
"number": 23, // "number": 23,
"text": "\"Then, we put the house together,\"" // "text": "\"Then, we put the house together,\""
}, // },
{ // {
"number": 23, // "number": 23,
"text": "says Hank." // "text": "says Hank."
}, // },
{ // {
"number": 24, // "number": 24,
"text": "“I'll hold the nails. You can pound them in,\"says Sophie." // "text": "“I'll hold the nails. You can pound them in,\"says Sophie."
}, // },
{ // {
"number": 24, // "number": 24,
"text": "\"Great!\"says Hank." // "text": "\"Great!\"says Hank."
}, // },
{ // {
"number": 25, // "number": 25,
"text": "\"Now we paint it,\" says Hank." // "text": "\"Now we paint it,\" says Hank."
}, // },
{ // {
"number": 26, // "number": 26,
"text": "\"We can all do that,\" says Sophie." // "text": "\"We can all do that,\" says Sophie."
}, // },
{ // {
"number": 26, // "number": 26,
"text": "\"Great!\" says Hank." // "text": "\"Great!\" says Hank."
}, // },
{ // {
"number": 27, // "number": 27,
"text": "The birdhouse is done. The tool team sets it on the table next to the other ones." // "text": "The birdhouse is done. The tool team sets it on the table next to the other ones."
}, // },
{ // {
"number": 28, // "number": 28,
"text": "\"It's prefect,\"says Hank." // "text": "\"It's prefect,\"says Hank."
}, // },
{ // {
"number": 29, // "number": 29,
"text": "“I think we built the best one,\"" // "text": "“I think we built the best one,\""
}, // },
{ // {
"number": 29, // "number": 29,
"text": "says Sammy." // "text": "says Sammy."
}, // },
{ // {
"number": 30, // "number": 30,
"text": "\"And we did it together,\" says Tia." // "text": "\"And we did it together,\" says Tia."
}, // },
{ // {
"number": 31, // "number": 31,
"text": "\"I have one more thing to add,\"" // "text": "\"I have one more thing to add,\""
}, // },
{ // {
"number": 31, // "number": 31,
"text": "says Hank." // "text": "says Hank."
}, // },
{ // {
"number": 32, // "number": 32,
"text": "\"Now it's perfect,\" says Sammy." // "text": "\"Now it's perfect,\" says Sammy."
} // }
] // ]
} // }
this.bookTextList = resData1.data; // this.bookTextList = resData1.data;
return; // this.bookTextList = this.filterDuplicateText( this.bookTextList);
console.log(' in getBookTextLis');
// return;
console.log(' in getBookTextList');
const call_back = (res) => { const call_back = (res) => {
console.log('getBookTextLis res: ', res); console.log('getBookTextList res: ', res);
const resData = JSON.parse(res); const resData = JSON.parse(res);
if (resData.msg == 'success') { if (resData.msg == 'success') {
...@@ -622,6 +643,9 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy { ...@@ -622,6 +643,9 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
}; };
checkAndCall(); checkAndCall();
this.bookTextList = this.filterDuplicateText( this.bookTextList);
} }
getRandomList(arr) { getRandomList(arr) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment