How can I use a dmx-repeat in javascript?

A part of my website requires me to use the write() method of writing javascript to html. This works fine when extracting data from App Connect with dmx.parse.

eg.

var check_id = dmx.parse('serverconnect1.data.getResult.id');

which I can use like this:

document.write("<div dmx-bind:id="' + check_id + '"></div>");

However, I can’t seem to use the same procedure to create a functioning repeater.

eg.

var repeater = dmx.parse('serverconnect1.data.getResult');

used something like this:

document.write("<div dmx-repeat:repeat_position="' + repeater + '">Repeat Content Goes Here</div>");

Does anyone know how to achieve this?

You can’t do it like that. You would have to assign the result array to a variable and use a javascript loop to iterate through it. Something like this:

var repeater = dmx.parse('serverconnect1.data.getResult');

for (i = 0; i < repeater.length; i++){
document.write("<div>My repeat ID is: "+repeater[i].id+"</div>");
}

Thanks bpj. I have implemented your javascript loop suggestion and it is now working.

Hi, I am having simlar issue. Where do I insert this js code. Is in the the script tag of the page or seperate js file?

To a large degree, it doesn’t matter whether it is in script tags or a separate file. What matters more is timing. I would typically put this in a function that is called on success of the server connect that feeds the data to it.