Pārlūkot izejas kodu

[search] Allow and render fields with dots in their name in the result template

Enrico Berti 12 gadi atpakaļ
vecāks
revīzija
d6d1c0c
1 mainītis faili ar 16 papildinājumiem un 1 dzēšanām
  1. 16 1
      apps/search/src/search/templates/search.mako

+ 16 - 1
apps/search/src/search/templates/search.mako

@@ -216,8 +216,23 @@ ${ commonheader(_('Search'), "search", user, "40px") | n,unicode }
               }
             }
           };
+
+          // fix the fields that contain dots in the name
+          for (var prop in item) {
+            if (item.hasOwnProperty(prop) && prop.indexOf(".") > -1) {
+              item[prop.replace(/\./gi, "_")] = item[prop];
+            }
+          }
+          var _mustacheTmpl = $("#mustacheTmpl").text();
+          var _mustacheTags = _mustacheTmpl.match(/{{(.*?)}}/g);
+          $.each(_mustacheTags, function (cnt, tag) {
+            if (tag.indexOf(".") > -1) {
+              _mustacheTmpl = _mustacheTmpl.replace(tag, tag.replace(/\./gi, "_"))
+            }
+          });
+
           $("<div>").addClass("result-row").html(
-            Mustache.render($("#mustacheTmpl").text(), item)
+            Mustache.render(_mustacheTmpl, item)
           ).appendTo($("#result-container"));
         });
       </script>