2

I'm using Views Module. I created a new ContentType with 3 custom fields: (text)Criteria, (decimal)Monthly, (decimal)Semester.

I created a table style view that retrieved the ContentType I created and dropped the values into a table. I'm actually using Javascript to grab the contents of each row generating a JSON array of objects with key-value-pairs for the content of the table, then I'm doing some fancy Javascript rendering. It's just a quick way to leverage Drupal's views and get the data where I want it exactly.

Anyway, when I grab the content of the Title row, $(this).find('td.views-field-title a').text();, it works fine, but when I try the exact same thing with the other 3 rows, I end up with a lot of space and \n. So my object ends up looking like:

[
 {'title':'Correct Title','criteria':'\n     Criteria Title    ','monthly':'\n     $70.00     '},
 {...},
 {...}
]

I can't figure out where the \n and extra space is coming from. It seems to be how the view formats the fields. How can I get rid of those?

Note: I do have the fields set to Plain Text in the configuration.

1 Answer 1

0

I checked this in my site and this is indeed default behaviour of Views. The easiest way to fix this is by changing your code to:

$.trim($(this).find('td.views-field-title a').text());
1
  • Worked like a charm. I was doing a regex replace, but trim works. ;)
    – user16124
    Mar 29, 2013 at 21:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.