Sorry if this is long-winded. I'll stick a tldr at the end.
I don't have any development experience, but at my job I occasionally need to use jQuery to manipulate HMTL pages. I've skated by piecing together bits and pieces from the jQuery documentation/various blogs/StackOverflow.
Lately I've been trying to actually understand what is happening rather than just blindly copying and pasting until something works -- which is what this question relates to.
Here is my current project:
Audience
Like 6 people on my team, so I generally don't need to worry about browser compatibility or whatever.
Use Case
We need to do clean-up work on our documentation.
Sally goes to a page with a drop-down menu. In the menu is a list of 10 products. She selects one, and a table appears containing product-specific search results.
She reviews the results, clicks the links provided to go fix the source. If a certain result is a false positive or doesn't need to be fixed, she selects the row with a checkbox and clicks a button. That result no longer appears in future searches.
Notes
The search is done through the API provided by our SaaS. Results are returned in XML, formatted as an RSS feed. There is a limit to the constraints I can include in the query, so for 3 products I have to apply additional filters on the results.
What I've Done
I still have to figure out the whole bit about putting/pulling IDs from a hidden div, but I've got some of the bigger pieces ready.
First, here is the HTML I have in place:
This is an example of what the XML looks like:
- //url list
- redURL='https://example.com?query=blah';
-
- //4 callbacks in total
- var fnListRed = $.Callbacks();
-
- function redTable(data) {
- var $XML = $(data),
- $tbody = $('#resultRows'),
- $trs = [];
- $XML.find("path:contains(5.6)").parent().remove();
- $XML.find("item").each(function () {
- var $this = $(this),
- item = {
- title: $this.find("title").text(),
- path: $this.find("path").text(),
- id: $this.find("page\\.id").text()
- },
- $tr = $('<tr>');
- $.each(item, function (i, item1) {
- $('<td>').html(item1).appendTo($tr);
- });
- $trs.push($tr);
- });
- $tbody.append($trs);
- };
-
- fnListRed.add(redTable);
-
- function prepColumns() {
- $('#resultRows tr').each(function () {
- var $col2 = $(this).find("td").slice(1, 2),
- $col2text = $col2.text();
- $col2.wrapInner("<a href='https://example.com/" + $col2text + "' </a>");
- });
- };
-
- fnListRed.add(prepColumns);
- //there are a few more functions in each callback list, so I hope this isn't as unnecessary as it looks
-
- function displayRedResults (data) {
- var $XML = $(data);
- fnListRed.fire($XML);
- };
-
- $(document).ready(function () {
-
- //Drop-down menu
- $( '#selectProduct' ).change(function () {
- var str = "";
- $( "#selectProduct option:selected" ).each(function () {
- str += $( this ).val();
- });
- if (str == "red") {
- $.get(redURL, displayRedResults);
- } else if (str == "blue") {
- $.get(blueURL, displayResults);
- //etc. etc
- });
- });
Actual Question/tl;dr
item.path
to manipulate it. I was trying to figure out if it had an index, but it seems like every character string is indexed separately (lines 36 and 37)