嗨創建方法,我想創作一個jQuery插件,我需要有元素訪問的方法,他們作爲那樣的對象,如初始化後:上飛
$('.list').list({some options}); //This initializes .list as a list
//now I want it to have certain methods like:
$('.list').find('List item'); //does some logic that I need
我
嘗試$.fn.list = function (options) {
return this.each(function() {
// some code here
this.find = function(test) {
//function logic
}
}
}
和其他幾個不同的嘗試,我只是不知道該怎麼做。
編輯:
我會盡力解釋這一點。
我想把一張桌子變成一個列表,基本上就像列計算機上的列標題和可排序項目和一切之間的一個列表。您啓動表像
$(this).list({
data: [{id: 1, name:'My First List Item', date:'2010/06/26'}, {id:2, name:'Second', date:'2010/05/20'}]
});
.list
命令將使<tbody>
排序,並做了一些其他的初始任務,然後將下面的方法添加到元素:
.findItem(condition)
將允許您找到某個項目條件(如findItem('name == "Second"')
.list(condition)
會列出符合給定條件的所有項目
.sort(key)
將所有物品通過給定的關鍵
等
要做到這一點,最好的方法是什麼?
你能提供更多的例子嗎?很難說你在做什麼......並且['.find()'](http://api.jquery.com/find/)已被採納:) – 2010-06-26 19:07:53
可能的重複[如何創建一個jQuery插件與方法?](http://stackoverflow.com/questions/1117086/how-to-create-a-jquery-plugin-with-methods) – redsquare 2010-06-26 19:09:32
標題是誤導,這些不是飛行中創建的方法。 – Anurag 2010-06-26 21:40:30