小胡子模板函数调用不起作用

时间:2014-01-09 04:54:59

标签: jquery mustache

尝试使用小胡子进行函数调用获取Uncaught TypeError:undefined不是函数。不知道什么是错误的文件很糟糕。希望它在搜索栏中显示而不是评分图像。

http://jsfiddle.net/JhsmB/

$('#search-fld').typeahead([{                              
    name: 'best-picture-winners',
    local: 
[
  {
    "year": "1961",
    "value": "West Side Story",
    "rating": "PG13",
    "wrapped": function () { return function (text, render) {
       return "<img src=" + render(text) + ".jpg>";
    }
  },
    "tokens": [
      "West",
      "Side",
      "Story"
    ]
  },
  {
    "year": "1962",
    "value": "Lawrence of Arabia",
     "rating": "PG",
    "wrapped": function () { return function (text, render) {
      return "<img src=" + render(text) + ".jpg>";
    }
  },
    "tokens": [
      "Lawrence",
      "of",
      "Arabia"
    ]
  },
  {
    "year": "1963",
    "value": "Tom Jones",
    "rating": "R",
     "wrapped": function () { return function (text, render) {
       return "<img src=" + render(text) + ".jpg>";
    }
  },
    "tokens": [
      "Tom",
      "Jones"
    ]
  }
],

template: '<p><strong>{{value}}</strong> – ({{year}} -  {{#wrapped}}{{rating}}{{/wrapped}}',                                                                 
engine: Hogan                                                         
}]);

1 个答案:

答案 0 :(得分:1)

好吧,我认为渲染不适用于Hogan.js。我已经更新了本地(基准面)。该数据也不正确。我也更新了包装器和模板。

希望这会有所帮助。 :)

$('#search-fld').typeahead([{
    name: 'best-picture-winners',
    local: [{
      "year": "1961",
      "value": "West Side Story",
      "rating": "PG13",
      "wrapped": function () { 
        return "<img src=" + this.rating + ".jpg/>";
      },
      "tokens": ["West","Side","Story"]
    },
    {
      "year": "1962",
      "value": "Lawrence of Arabia",
      "rating": "PG",
      "wrapped": function () { 
          return "<img src=" + this.rating + ".jpg/>";
      },
      "tokens": ["Lawrence","of","Arabia"]
    },
    {
      "year": "1963",
      "value": "Tom Jones",
      "rating": "R",
      "wrapped": function () { 
          return "<img src=" + this.rating + ".jpg/>";
      },
      "tokens": ["Tom","Jones"]
    }
  ],
  template: '<p><strong>{{value}}</strong> – ({{year}} -  {{{wrapped}}})',
  engine: Hogan
}]);

<强> DEMO