jQuery .data() and plugins
<p>I am trying to use jQuery's .data() tool in a jQuery plugin but I'm getting some odd results.
Here is a cut down version of my plugin with the relevant code:</p>

<pre><code>(function( $ ){ 

    var methods = {
        init : function( options ) { 

            // Do some stuff
            this.data('name', 'New Component');
            return this;
        },
        getStateData : function () {
            // Function returns all data for save
            var state = new Object;

            state.name =  this.data('name');

            // snip ... Add some other bits to state
            // ...

            return state;               
        },
        setStateData: function (args) {
            var key     = args[0];
            var value   = args[1];

            // snip
            this.data(key, value);
        }
    };

    $.fn.component7Segment = function(method) {
        if ( methods[method] ) {
            return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
        } else if ( typeof method === 'object' || ! method ) {
            return methods.init.apply( this, arguments );
        } else {
            $.error( 'Method ' +  method + ' does not exist on jQuery.designComponent' );
        }       
    };
})( jQuery );
</code></pre>

<p>If I call <code>$(instance-of-plugin).component7Segment('getStateData');</code> the plugin returns the correct 'name' however if I call <code>setStateData</code> to change the name it has not changed the 'name' value when I next call <code>getStateData</code>.</p>

<p>Doing <code>console.log(this);</code> in each function looks slightly different so I started trying:</p>

<pre><code>$.data($('#object-id'), 'name', value);
</code></pre>

<p>This still doesn't have the desired effect.</p>

<p>Can anybody see what I am missing?</p>
