4
假設我想要更改bootstrap-typeahead庫中的渲染函數。活躍這一目標 http://twitter.github.com/bootstrap/assets/js/bootstrap-typeahead.js在jQuery庫中重新定義方法的最佳方式
一種方法是使:
_.extend($.fn.typeahead.Constructor.prototype, {
render: function (items) {
// some code
}
});
讓我們假設我要重新定義渲染功能只爲特定元素像...
element.typeahead({
minLength: 3,
source: getSource
});
我應該如何重新定義渲染函數爲了只對這個元素有效?
P.S:
我使用jQuery和強調
我試過,但它不工作,因爲'$ .fn.typeahead.Constructor.prototype.render'是更改 –
也許你需要深入克隆'$ .fn.typeaheadCustom = $ .extend(true,$ .fn.typeahead,{});' – David
也可以使'$ .extend(true,$ .fn.typeahead,{ });'它不起作用。 –