2014-01-09 61 views
0

試圖做一個帶鬍子的函數調用獲取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               
}]); 
+0

什麼是渲染?任何定義的渲染?控制檯錯誤:渲染不是一個函數。什麼是傳遞給函數的文本參數。 –

+0

@maheshSapkal它是鬍鬚模板引擎的一部分,http://mustache.github.io/mustache.5.html,我不知道它爲什麼不起作用 – Edward

+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

+0

好的,讓我試試這個與我的遠程源,如果它工作不正常愛你永遠 – Edward