I like to get all values of the repeater inside jQuery or javascript. Does anybody know how to do this?
thnx in advance
I like to get all values of the repeater inside jQuery or javascript. Does anybody know how to do this?
thnx in advance
Since youâre asking for this, iâm going to assume you are comfortable with the various ways to get JS into axure prototypesâŚ
Hereâs a function that will return an array of arrays with the data. Credit @sam.hepworth for his amazing work in the AxureEX library - this is mostly all his work - I just packaged it into a function designed to spit out the the data.
There are two helper function included called âgetRepeaterâ and âgetIDfromAxureNameâ as well as a global variable making it easier to call the internal axure functions.
What youâd call is the âgetRepeaterDataâ function. Pass it the distinct name (defined in the properties section of the widget in the Axure UI) of a repeater and it will return an array of the data.
example: getRepeaterData(âmyRepeatersNameâ);
// Assign public $ax Variable for internal functions
var $ax;
$axure.internal(function(ax) {
$ax = ax;
});
// Find repeater object with given id
function getRepeater(repeaterId) {
var repeater;
$axure(function(obj) {
return obj.type == 'repeater';
}).each(function(obj, id) {
if (id == repeaterId) {
repeater = obj;
}
});
return repeater;
}
// Get ID from Axure Name assigned in Widget Properties
function getIDfromAxureName(axureName) {
return $axure('@' + axureName).getElementIds()[0];
}
// Get data from repeater
// axureName: Name of repeater widget (assigned in UI)
function getRepeaterData(axureName) {
var repeaterId = getIDfromAxureName(axureName)
var ids = $ax.repeater.getAllItemIds(repeaterId);
var columns = getRepeater(repeaterId).dataProps;
rows = [];
for (var i = 0, il = ids.length; i < il; i++) {
var row = {};
for (var j = 0, jl = columns.length; j < jl; j++) {
var name = columns[j].toLowerCase();
var id = ids[i];
if ((typeof (id) == 'string') && (id.indexOf('-') != -1))
id = $ax.repeater.getItemIdFromElementId(id);
var value = $ax.repeater.getData({}, repeaterId, ids[i], name, 'data');
if (typeof (value) == 'object') {
value = $ax.deepCopy(value);
if (value.type === undefined)
value.type = 'text';
row[name] = value;
} else {
row[name] = {
type: 'text',
text: value
};
}
}
rows.push(row);
}
return rows;
}
;
The above answer is very good and clear. Iâm just sharing some code I dug up from probably 4 years ago when I needed to do some multi-repeater hacking. This is a bit that will get you an object containing all repeaters keyed by id with an array of the repeaterâs contents and column names separately.
$axure.internal(function($ax){
window.$axure.repeater = $ax.repeater;
window.repeaterToLocalDataSet = {};
$ax(function(obj) {
return obj.type == 'repeater';
}).each(function(obj, repeaterId) {
repeaterToLocalDataSet[repeaterId] = $ax.deepCopy(obj.data);
repeaterToLocalDataSet[repeaterId].props = obj.dataProps;
console.log(repeaterToLocalDataSet)
});
});
This was before Axure improved repeater formatting options and I needed to apply my own styling to get a fluid table layout.
Nice⌠digging the simplicity!
Thanks a lot! works like a charm!
I see the array structure, but I cannot find the entryâs of the repeater it self. Can you help me wich array element contains the entries of the repeater.
example_repeater.rp (130.2 KB)
What Iâm trying to achieve is:
a array variable with only the labels and the contents of the repeater.
so:
Question 1 :
Answer 1:
Action 1
Question 2:
Answer 2:
Action 2:
etc.
See my attachment as example
So when I run nkriscâs code in one of my prototypes, I get a much different result than running in yours. I think itâs because youâre adding all of your rows in page load events and the mechanism his code uses looks at the initial data set?
I know mine looks quite a bit more complicated, but it does seem to work to give the data youâre looking for when I run it in the console.
Itâs been a long time since I dug into the internals of repeaters, but it may be a case of order of operations. I skimmed the first code and in both instances, it looks like youâre not getting a reference to the repeater data, but a copy of it. So if you change it after the fact your copy wonât update.
If you have data being added on page load, make sure the JS is run after that is finished. You might even need to add a small delay as it may not be synchronous.
Really though if you want to programmatically access repeater data with JS Iâd start digging around the internal repeater.js file to see how things work. I did that once, but I probably wouldnât again.
I canât get your code to work get several errors in the console? Can you upload a working example?
I try to add the delay, still not working. It sure has something to do by adding the values later. Your code is working with a standard repeater.
Right, of you run this code after you add the values, does it work?
Yep, didnt work either
Gotcha. Not to sure then. Maybe something has changed as itâs been a few years since I used this code, or out just never worked that way and I donât remember.
Hereâs an example that will log your repeater data to the console on load. Iâve never been a fan of the js engine approach - I use open link event. You can also put stuff in using web fonts, too.
Youâll see my new action as the last item in the onPageLoad events.
I think regardless of how you add it, the comments tend to be problematic unless you use the web font hack - I was also missing a semi-colon line break on a line which may have been throwing an error.
Take a look and see if you can leverage what I did to get what youâre looking for.
example_repeater (2).rp (130.9 KB)
Many thanx now I can move on! great!
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.