Welcome Guest, Not a member yet? Register   Sign In
Codeigniter Clone In jQuery
#6

[eluser]Alex Lawford[/eluser]
Hi, would this achieve what you were after do you think?
Code:
// example... an array of objects
var people = [{ name : john, age : 24 }, { name : alice, age : 31 }, { name : sam, age : 44 }];

view_looper(people, function(string){
    alert(string);
});

function view_looper(ob_array, callback)
{
    output = new Array();
    $.each(ob_array, function(key, val){
        load.view("my_view", val, true, function(string){
            // this ensures it is in the correct order which is not guaranteed given the
            // asynch nature of the load.view function
            output[key] = string;
            // last time
            if(val === (ob_array.length - 1) )
            {
                output = output.join("");
                callback(output);
            }
        }
    });
}

Then if "my_view.html" looked liked this:

Code:
<dl>
<dt>Name:</dt>
<dd>[name]</dd>
<dt>Age:</dt>
<dd>[age]</dd>
</dl>

The following would be returned:

Code:
<dl>
<dt>Name:</dt>
<dd>John</dd>
<dt>Age:</dt>
<dd>24</dd>
</dl>
<dl>
<dt>Name:</dt>
<dd>Alice</dd>
<dt>Age:</dt>
<dd>31</dd>
</dl>
<dl>
<dt>Name:</dt>
<dd>Sam</dd>
<dt>Age:</dt>
<dd>44</dd>
</dl>


Messages In This Thread
Codeigniter Clone In jQuery - by El Forum - 07-10-2010, 02:47 AM
Codeigniter Clone In jQuery - by El Forum - 07-10-2010, 01:35 PM
Codeigniter Clone In jQuery - by El Forum - 07-10-2010, 06:48 PM
Codeigniter Clone In jQuery - by El Forum - 07-10-2010, 08:34 PM
Codeigniter Clone In jQuery - by El Forum - 07-11-2010, 08:36 AM
Codeigniter Clone In jQuery - by El Forum - 07-12-2010, 09:58 PM
Codeigniter Clone In jQuery - by El Forum - 07-13-2010, 01:34 PM
Codeigniter Clone In jQuery - by El Forum - 09-24-2010, 02:27 AM



Theme © iAndrew 2016 - Forum software by © MyBB