Kaynağa Gözat

:sparkles: 术语表增加排序

visuddhinanda@gmail.com 4 yıl önce
ebeveyn
işleme
fd39cec179

+ 9 - 2
public/app/article/templiates/glossary.tpl

@@ -1,6 +1,13 @@
 <h2>Glossary</h2>
 <h2>Glossary</h2>
-{{#glossary}}
+{{#glossary.word}}
 <div>
 <div>
 <b>{{pali}}</b>:{{meaning}}
 <b>{{pali}}</b>:{{meaning}}
 </div>
 </div>
-{{/glossary}}
+{{/glossary.word}}
+
+<h2>术语表</h2>
+{{#glossary.meaning}}
+<div>
+<b>{{meaning}}</b>:{{pali}}
+</div>
+{{/glossary.meaning}}

+ 47 - 5
public/app/term/term.js

@@ -719,13 +719,55 @@ function term_get_dict() {
 function term_get_used(){
 function term_get_used(){
     let output = [];
     let output = [];
     $("term").each(function () {
     $("term").each(function () {
-        output.push({
-            pali:$(this).attr("pali"),
-            meaning:$(this).attr("mean")
-        });
+        let word = $(this).attr("pali");
+        let meaning = $(this).attr("mean");
+        if(word !== ""){
+            output[word] = {
+                pali:word,
+                pali_en:com_getPaliEn(word),
+                meaning:meaning
+            };
+        }
+
     });
     });
+
+    let arrWord=[];
+    for (const key in output) {
+        if (output.hasOwnProperty.call(output, key)) {
+            const element = output[key];
+            arrWord.push(element);
+        }
+    }
+    arrWord = arrWord.sort(function(a, b){
+	  var x = a.pali_en;
+	  var y = b.pali_en;
+	  if (x < y) {return -1;}
+	  if (x > y) {return 1;}
+	  return 0;
+        });
+
+    let arrMeaning=[];
+    for (const key in output) {
+        if (output.hasOwnProperty.call(output, key)) {
+            const element = output[key];
+            if(element.meaning != ""){
+                arrMeaning.push(element);
+            }
+        }
+    }
+    arrMeaning = arrMeaning.sort(function(a, b){
+	  var x = a.meaning;
+	  var y = b.meaning;
+	  if (x < y) {return -1;}
+	  if (x > y) {return 1;}
+	  return 0;
+        });
+
     return {
     return {
-        glossary:output
+        glossary:{
+            word:arrWord,
+            meaning:arrMeaning
+        }
     }
     }
 }
 }
 /*
 /*