Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript, adding things in curly bracket and definition
    primarykey
    data
    text
    <p>i'm in the process of modifying this excellent javascript library for autocomplete-ing html input <a href="http://www.devbridge.com/projects/autocomplete/" rel="nofollow">see here</a>... as i need to pass some extraparameters to the Ajax call. Actually i'm looking for something non destructive so that it can manage a default behaviour of this lib, that will also be able to handle "no extraparameters". </p> <p>so i think i will have a call like </p> <pre><code>myExtra = {b : 'b', c: 'c'} // or maybe a thing like myExtra = "{b : 'b', c: 'c'}" myAutoComplete = new Autocomplete('query', { serviceUrl:'autoComplete.rails'}, myExtra); </code></pre> <p>with a null test for myExtra that does nothing if null or 'add' the content of myExtra to the Ajax request, so that this part:</p> <pre><code> new Ajax.Request(this.serviceUrl, { parameters: { query: this.currentValue , }, onComplete: this.processResponse.bind(this), method: 'get' }); </code></pre> <p>become something like when myExtra is not null or empty string:</p> <pre><code> new Ajax.Request(this.serviceUrl, { parameters: { query: this.currentValue , b: 'b', c: 'c'}, onComplete: this.processResponse.bind(this), method: 'get' }); </code></pre> <p>as i'm brand new to web developpment, my trouble is that i do not know how to add curly bracktetted content {} to another one (and i'm not sure that i even understand well what are these {}...)</p> <p>i think i want to do this king of things that Python accept, but i just do not know how Javascript can do that, </p> <pre><code> &gt;&gt;&gt; class A: def __init__(self, data): self.data = data &gt;&gt;&gt; a = A("my data") &gt;&gt;&gt; dir(a) ['__doc__', '__init__', '__module__', 'data'] &gt;&gt;&gt; myExtra = "b='b';c='c'" &gt;&gt;&gt; for x in myExtra.split(";"): var, value = x.split('=') setattr(a, var, value) &gt;&gt;&gt; dir(a) ['__doc__', '__init__', '__module__', 'b', 'c', 'data'] &gt;&gt;&gt; print a.data, a.b, a.c my data 'b' 'c' </code></pre> <p>so please, if you have any pointers for understanding this, Thank you in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload