开发者

jquery .each objects

i am building an jQuery plugin, but i want to use objects in the options var, how can i loop this with the jQuery each?

plugin options var

        var defaults = {
            test: 'yes',   //css/classes
            type: {
                minvalue: '100',
                maxvalue: '200',
                name: 'id1'
            },
            type: {
                minvalue: '200',
                maxvalue: '300',
                name: 'id2'
            },
            type: {
                minvalue: '300',
                maxvalue: '400',
                name: 'id3'
            }               
        };


            $.each(defaults, function(key, value) { 
              alert(ke开发者_开发技巧y + ': ' + value); 
            });  


With your example it is a bit difficult to figure what exactly you are trying to do, but if you want to use arrays and $.each, you could do this:

 var defaults = {
            test: 'yes',   //css/classes
     types: [
         {
                minvalue: '100',
                maxvalue: '200',
                name: 'id1'
            },
         {
                minvalue: '200',
                maxvalue: '300',
                name: 'id2'
            },
         {
                minvalue: '300',
                maxvalue: '400',
                name: 'id3'
            }


         ]

        };

$.each(defaults.types, function(index, value) { 
              alert(value.name + ': ' + value.minvalue); 
            }); 

http://jsfiddle.net/niklasvh/kFjVN/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜