2

Peace of mustache template:

        <span class="frameSpec blackBg">{{#i18n}}Kids{{/i18n}}</span>

Peace of javascript code:

// Preparing data to view
var items = {
            'items': data.matches,
            'i18n' : function(){
               return get_translation(key);
             }
            };
        //--

$("#items").append(Mustache.render(items_template, items));

This doesn't work, key always is undefinded?

Andrii Tarykin
  • 568
  • 2
  • 6
  • 24
  • Where does `key` come from? It's not mentioned anywhere else in your code other than when trying to call the `get_translation` function. – Anthony Grist Nov 20 '13 at 11:39
  • Possible duplicate of [calling function with arguments in mustache javascript](http://stackoverflow.com/questions/6045165/calling-function-with-arguments-in-mustache-javascript) – Emile Bergeron Mar 14 '16 at 14:51

2 Answers2

4

This is the fix for my code:

// Preparing data to view
var items = {
    'items': data.matches,
    'i18n' : function(){
        return function(key){
            return get_translation(key);
        }
     }
};
//--
Pang
  • 8,605
  • 144
  • 77
  • 113
Andrii Tarykin
  • 568
  • 2
  • 6
  • 24
0

Maybe you should type the function like that:

'i18n' : function(key) {
   return get_translation(key);
}

I.e. the key variable is not defined and probably is passed as a parameter of your function.

Krasimir
  • 12,605
  • 3
  • 34
  • 52