Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Raskolnikov2089
Nov 3, 2006

Schizzy to the matic
Another newbie question here -


JavaScript code:
var cipher = "I said, 'A line will take us hours maybe; " +
"Yet if it does not seem a moment’s thought, ";    


//remove punctuation
var cipherPunctuation = cipher.replace(/[\.,-\/#!$%\^'&'\*;:{}=\-_`~()]/g,"");


//remove whitespace
var cipherWspace = cipherPunctuation.replace(/ /g,'');


//remove apostrophes
var cipherStripped3 = cipherWspace.replace(/'/g,'');

console.log(cipherStripped3);

I'm trying to take a string, remove all punctuation, followed by all whitespace. All seems to be well, however the 's from " moment's " is not being stripped no matter what I try. The first apostrophe in the string is caught by cipherPunctuation, but nothing I can google will remove that second apostrophe.

Please tell me what mind-numbingly obvious thing I'm missing so I can stop mumbling to my text editor.

Adbot
ADBOT LOVES YOU

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Raskolnikov2089 posted:

Another newbie question here -


JavaScript code:
var cipher = "I said, 'A line will take us hours maybe; " +
"Yet if it does not seem a moment’s thought, ";    


//remove punctuation
var cipherPunctuation = cipher.replace(/[\.,-\/#!$%\^'&'\*;:{}=\-_`~()]/g,"");


//remove whitespace
var cipherWspace = cipherPunctuation.replace(/ /g,'');


//remove apostrophes
var cipherStripped3 = cipherWspace.replace(/'/g,'');

console.log(cipherStripped3);

I'm trying to take a string, remove all punctuation, followed by all whitespace. All seems to be well, however the 's from " moment's " is not being stripped no matter what I try. The first apostrophe in the string is caught by cipherPunctuation, but nothing I can google will remove that second apostrophe.

Please tell me what mind-numbingly obvious thing I'm missing so I can stop mumbling to my text editor.

You need to escape the character.

try
JavaScript code:
var cipherStripped3 = cipherWspace.replace(/\'/g,'');
Edit: you also need to remove the single quotes in the first replace.

Raskolnikov2089
Nov 3, 2006

Schizzy to the matic

Strong Sauce posted:

You need to escape the character.

try
JavaScript code:
var cipherStripped3 = cipherWspace.replace(/\'/g,'');
Edit: you also need to remove the single quotes in the first replace.

I found and tried a similar suggestion on Stack Overflow, but it still outputs as:

JavaScript code:
IsaidAlinewilltakeushoursmaybeYetifitdoesnotseemamoment’sthought 

obstipator
Nov 8, 2009

by FactsAreUseless
The apostrophe is one of those slanted ones that sometimes get replaced in word documents or whatever, because it "looks fancier". Either add that slanted one to the list, or use the char code for it. The apostrophe might be getting converted to a real apostrophe on save, which is effectively removing the fancy apostrophe from the list.

Both of these should work:

/[\.,-\/#!$%\^'&'\*;:{}=\-_`~()’]/g

or this one if the character gets converted:

/[\.,-\/#!$%\^'&'\*;:{}=\-_`~()\u2019]/g

Raskolnikov2089
Nov 3, 2006

Schizzy to the matic

obstipator posted:

The apostrophe is one of those slanted ones that sometimes get replaced in word documents or whatever, because it "looks fancier". Either add that slanted one to the list, or use the char code for it. The apostrophe might be getting converted to a real apostrophe on save, which is effectively removing the fancy apostrophe from the list.

Both of these should work:

/[\.,-\/#!$%\^'&'\*;:{}=\-_`~()’]/g

or this one if the character gets converted:

/[\.,-\/#!$%\^'&'\*;:{}=\-_`~()\u2019]/g

I just realized I copied it from Word.

Ok I'll commence banging my head on the desk. Fun lesson. Thank you.

Raskolnikov2089 fucked around with this message at 04:35 on Dec 17, 2013

Raskolnikov2089
Nov 3, 2006

Schizzy to the matic
JavaScript code:
      function arrayCounter(x){
        if (typeof x === 'string' || 'number' || 'undefined')
	{
        	return 0;
        }
        else
	{
          return x.length;
        }
      };
The above only works if I give each || statement it's own typeof operator. i.e.


JavaScript code:
      function arrayCounter(x){
        if (typeof x === 'string' || 
	    typeof x === 'number' || 
	    typeof x === 'undefined')
	{
        	return 0;
        }
        else
	{
          return x.length;
        }
      };
Is this a particular quirk of typeof, or am I just assuming javascript is a lot more intuitive than it actually is?



vvv That makes sense (and is kind of fascinating). thank you.

Raskolnikov2089 fucked around with this message at 23:06 on Dec 29, 2013

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



Raskolnikov2089 posted:

JavaScript code:
      function arrayCounter(x){
        if (typeof x === 'string' || 'number' || 'undefined')
	{
        	return 0;
        }
        else
	{
          return x.length;
        }
      };
The above only works if I give each || statement it's own typeof operator. i.e.


JavaScript code:
      function arrayCounter(x){
        if (typeof x === 'string' || 
	    typeof x === 'number' || 
	    typeof x === 'undefined')
	{
        	return 0;
        }
        else
	{
          return x.length;
        }
      };
Is this a particular quirk of typeof, or am I just assuming javascript is a lot more intuitive than it actually is?

What "(typeof x === 'string' || 'number' || 'undefined')" really means to javascript is:

"typeof x === 'string'"
OR
"'number'"
OR
"'undefined'"

not:

"typeof x === 'string'"
OR
"typeof x === 'number'"
OR
"typeof x === 'undefined'"

like you wanted.

It may seem intuitive to only have the one "typeof x ===" but consider if you wanted an if statement that was like:

if (typeof x === 'string' || x) {...}

Where you wanted it to be either "the typeof x is string" OR "x has a value", you wouldn't be able to do that if javascript assumed you meant "typeof x is string" OR "typeof x is x".

piratepilates fucked around with this message at 21:06 on Dec 29, 2013

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Raskolnikov2089 posted:

Is this a particular quirk of typeof, or am I just assuming javascript is a lot more intuitive than it actually is?

There is one place where you can use a syntax similar to that in Javascript, and that is to give variables default values:

var x = someOtherValue || "The default value";

If someOtherValue is "truthy" (so not false, undefined, null, 0, NaN, or empty string) x is set to that. If it is "falsy", it is set to "The default value".

MonkeyMaker
May 22, 2006

What's your poison, sir?

Raskolnikov2089 posted:

JavaScript code:
      function arrayCounter(x){
        if (typeof x === 'string' || 'number' || 'undefined')
	{
        	return 0;
        }
        else
	{
          return x.length;
        }
      };
The above only works if I give each || statement it's own typeof operator. i.e.


JavaScript code:
      function arrayCounter(x){
        if (typeof x === 'string' || 
	    typeof x === 'number' || 
	    typeof x === 'undefined')
	{
        	return 0;
        }
        else
	{
          return x.length;
        }
      };
Is this a particular quirk of typeof, or am I just assuming javascript is a lot more intuitive than it actually is?



vvv That makes sense (and is kind of fascinating). thank you.

JavaScript code:
switch (typeof(x)) {
    case 'string':
    case 'number':
    case 'undefined':
        return 0;
        break;
    default:
        return x.length;
        break;
}
yes?

hedgecore
May 2, 2004

Raskolnikov2089 posted:

JavaScript code:
      function arrayCounter(x)
Is this a particular quirk of typeof, or am I just assuming javascript is a lot more intuitive than it actually is?

Another way you can do this:
JavaScript code:
function arrayCounter(x) {
	if (['string', 'number', 'undefined'].indexOf(typeof x) > -1) {
		return 0;
	} else {
		return x.length;
	}
};
It's not necessarily useful for type checking, but if you want to check if a value exists within a few options, you can test if it's in an array of those options via indexOf().

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Wheany posted:

There is one place where you can use a syntax similar to that in Javascript, and that is to give variables default values:

var x = someOtherValue || "The default value";

If someOtherValue is "truthy" (so not false, undefined, null, 0, NaN, or empty string) x is set to that. If it is "falsy", it is set to "The default value".

If someOtherValue is undefined, it's an error and you get a big fat nothing. You could use window.someOtherValue to try to work around that, though.

darthbob88
Oct 13, 2011

YOSPOS

hedgecore posted:

Another way you can do this:
JavaScript code:
function arrayCounter(x) {
	if (['string', 'number', 'undefined'].indexOf(typeof x) > -1) {
		return 0;
	} else {
		return x.length;
	}
};
It's not necessarily useful for type checking, but if you want to check if a value exists within a few options, you can test if it's in an array of those options via indexOf().
Unfortunately, indexOf doesn't work on IE8. Some day soon that won't be a problem, but until then, you'll need polyfills.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Munkeymon posted:

If someOtherValue is undefined, it's an error and you get a big fat nothing. You could use window.someOtherValue to try to work around that, though.

Kind of. If the variable hasn't been defined, then yes it's an error - however, if the variable exists but has the value undefined, it works fine.

Notably, this works:
JavaScript code:
function foo(bar) {
  var actualBar = bar || "defaultBar";
  //...
}

foo() // Same as foo("defaultBar")
Since bar appears in the parameter list, the name exists, and the value will be undefined if it isn't specified when the function is called.

LP0 ON FIRE
Jan 25, 2006

beep boop
I'm trying to simply copy an array of arrays into an array using the example:

teamRedVelArrays = velArraysBackup.slice(0);

This doesn't seem to make my array of arrays change to the backup or vise-versa. Is it different for an array of arrays?

5TonsOfFlax
Aug 31, 2001

LP0 ON FIRE posted:

I'm trying to simply copy an array of arrays into an array using the example:

teamRedVelArrays = velArraysBackup.slice(0);

This doesn't seem to make my array of arrays change to the backup or vise-versa. Is it different for an array of arrays?

I can't quite tell what you're trying to ask, but using slice like that makes only a shallow copy. To clone your array values (which are themselves arrays here), you'll need to make a recursive copy function.

LP0 ON FIRE
Jan 25, 2006

beep boop

5TonsOfFlax posted:

I can't quite tell what you're trying to ask, but using slice like that makes only a shallow copy. To clone your array values (which are themselves arrays here), you'll need to make a recursive copy function.

What do you mean by shallow copy? Like it only copies the initial array and not the arrays inside of it? I originally had a recursive copy function that had the same issue I'm having now. Does it have to be two for loops, one inside the other for it to work?

I just had something like:

code:
for(i=0; i<maxSize; ++i){

     teamRedArrays[i] = velArraysBackup[i];

}
Even though every index of teamRedArrays had an array inside of it.

Edit: I found a function that did it. I guess it's more complicated than I think it should be?

code:

function backupArray(existingArray) {
   var newObj = (existingArray instanceof Array) ? [] : {};
   for (i in existingArray) {
      if (i == 'clone') continue;
      if (existingArray[i] && typeof existingArray[i] == "object") {
         newObj[i] = backupArray(existingArray[i]);
      } else {
         newObj[i] = existingArray[i]
      }
   }
   return newObj;
}

LP0 ON FIRE fucked around with this message at 19:17 on Jan 2, 2014

Zaxxon
Feb 14, 2004

Wir Tanzen Mekanik

LP0 ON FIRE posted:

This doesn't seem to make my array of arrays change to the backup or vise-versa. Is it different for an array of arrays?

can you be more specific with what you mean by this sentence? Maybe use an example with some code.
When I read this it sounds like what you are saying is:

code:
teamRedVelArrays = velArraysBackup.slice(0);
teamRedVelArrays === velArraysBackup //Should be true, but isn't!
is that the case?

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.

LP0 ON FIRE posted:

What do you mean by shallow copy? Like it only copies the initial array and not the arrays inside of it? I originally had a recursive copy function that had the same issue I'm having now. Does it have to be two for loops, one inside the other for it to work?

I just had something like:

code:
for(i=0; i<maxSize; ++i){

     teamRedArrays[i] = velArraysBackup[i];

}
Even though every index of teamRedArrays had an array inside of it.

Edit: I found a function that did it. I guess it's more complicated than I think it should be?

code:

function backupArray(existingArray) {
   var newObj = (existingArray instanceof Array) ? [] : {};
   for (i in existingArray) {
      if (i == 'clone') continue;
      if (existingArray[i] && typeof existingArray[i] == "object") {
         newObj[i] = backupArray(existingArray[i]);
      } else {
         newObj[i] = existingArray[i]
      }
   }
   return newObj;
}


A key thing about Javascript, (and a lot of other languages) is that objects only ever get assigned by REFERENCE. This is a key concept to understand.

code:
var obj1 = {val: 'string', foo: 'bar'}; // a new object
var obj2 = obj1; // object is assigned to the name obj2 as well
obj2.val = 'anotherstring'; // change a property of obj2
obj1.val === 'anotherstring'; // and you're in fact changing obj1 as well.
Arrays are objects too. Slice creates a shallow copy, so it's only a proper copy if all the elements inside are assigned by value, namely strings, integers, floats, that sort of thing. The function you found is a recursive function that copies an array by diving as deep as it needs to find elements it can pass by value, and then rebuilding the arrays and objects from scratch.

That's what is called a deep copy, and results in completely independant objects/arrays, they don't share values.

LP0 ON FIRE
Jan 25, 2006

beep boop

Maluco Marinero posted:

A key thing about Javascript, (and a lot of other languages) is that objects only ever get assigned by REFERENCE. This is a key concept to understand.

code:
var obj1 = {val: 'string', foo: 'bar'}; // a new object
var obj2 = obj1; // object is assigned to the name obj2 as well
obj2.val = 'anotherstring'; // change a property of obj2
obj1.val === 'anotherstring'; // and you're in fact changing obj1 as well.
Arrays are objects too. Slice creates a shallow copy, so it's only a proper copy if all the elements inside are assigned by value, namely strings, integers, floats, that sort of thing. The function you found is a recursive function that copies an array by diving as deep as it needs to find elements it can pass by value, and then rebuilding the arrays and objects from scratch.

That's what is called a deep copy, and results in completely independant objects/arrays, they don't share values.

Thanks for your advice. I'm really unfamiliar with javascript and I'm so used to having methods to just duplicate or point to other objects. I find it incredibly odd that I must loop through it to do a deep copy instead of a built-in function.

I'm having an issue with my script locking up sometimes, and I narrowed it down to calling a duplication method. I've tried lots that I've found online and they all have this problem. 

The last one I tried is this:

code:
Array.prototype.clone = function() {
    var arr = this.slice(0);
    for( var i = 0; i < this.length; i++ ) {
        if( this[i].clone ) {
            //recursion
            arr[i] = this[i].clone();
        }
    }
    return arr;
}
Setting an array this way:teamBlueVelArrays = teamBlueVelArraysBackup.clone();

I just want to add that teamBlueVelArrays and teamBlueVelArraysBackup are defined as arrays in the beginning of my script like: teamBlueVelArrays = new Array();

Anything obvious that's wrong with this? I'm doubting it. Otherwise I guess it's something else wrong it my code that is a direct result of cloning these arrays.

5TonsOfFlax
Aug 31, 2001
How big and how deep are these structures?

Depending on the sorts of items in these structures, you may be better served by serializing then reading back in using JSON.stringify and JSON.parse (in recent browsers).

Edit: You should almost never use new Array(). Just use a literal [].

obstipator
Nov 8, 2009

by FactsAreUseless
Check the error console (ctrl + shift + J in Chrome and FF) for more information on the error and what line it's coming from.

If there's an undefined or null value in that array somewhere, it'll cause an error when checking this if:
if( this[i].clone ) {

since this[i] might not be defined, and you'll be trying to get the value of a key of an undefined thing, which makes it throw an error.

An undefined can show up in an array if you define a later value to something, which I think might be what's causing this:
var a = [];
a[1] = 5;

a[0] would be undefined, and cause that if() to throw an error.

LP0 ON FIRE
Jan 25, 2006

beep boop

obstipator posted:

Check the error console (ctrl + shift + J in Chrome and FF) for more information on the error and what line it's coming from.

If there's an undefined or null value in that array somewhere, it'll cause an error when checking this if:
if( this[i].clone ) {

since this[i] might not be defined, and you'll be trying to get the value of a key of an undefined thing, which makes it throw an error.

An undefined can show up in an array if you define a later value to something, which I think might be what's causing this:
var a = [];
a[1] = 5;

a[0] would be undefined, and cause that if() to throw an error.

After a little investigation, it looks like this was it! :doh: I didn't have any primary definition of the velocity array backup indexes, and if they were ever used, then yup, no set values = freeze. It was so simple and I should have caught it, but it was never an issue before until I changed something in my code. Thanks :)


5TonsOfFlax posted:

How big and how deep are these structures?

Depending on the sorts of items in these structures, you may be better served by serializing then reading back in using JSON.stringify and JSON.parse (in recent browsers).

Edit: You should almost never use new Array(). Just use a literal [].

It's an array with an array inside every index at a set number of indexes. So I guess 2 levels?

About new Array() vs []: isn't defining [] mean that it's sort of immutable and new Array() mutable?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
new Array() and [] mean the exact same thing, but the latter is what you'll more commonly see.

LP0 ON FIRE
Jan 25, 2006

beep boop

Suspicious Dish posted:

new Array() and [] mean the exact same thing, but the latter is what you'll more commonly see.

Okay, so the difference between new Array() and [] (an array "literal") is just how they are written.

5TonsOfFlax
Aug 31, 2001

LP0 ON FIRE posted:

It's an array with an array inside every index at a set number of indexes. So I guess 2 levels?

I'm glad you seem to have fixed your clone issue. It sounds like you only have arrays and primitives (no objects with functions or multiple references to the same items that you need to keep the same), so the JSON stringify parse method should work for you and be very fast.
code:

function clone(obj) {
  return JSON.parse(JSON.stringify(obj));
}

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

LP0 ON FIRE posted:

Okay, so the difference between new Array() and [] (an array "literal") is just how they are written.

Correct.

5TonsOfFlax
Aug 31, 2001

LP0 ON FIRE posted:

Okay, so the difference between new Array() and [] (an array "literal") is just how they are written.

Semantically, yes. Usually. But not for performance (not an issue unless you have a shitload of arrays).
http://stackoverflow.com/questions/931872/whats-the-difference-between-array-and-while-declaring-a-javascript-ar

I just ran these tests in chrome:
code:
(function(){
  var start = (new Date()).getTime();
  for (var i = 0; i < 1000000; i++) {
    var a = [];
  }
  var end = (new Date()).getTime();
  return (end-start);
})()
returns 16 ms on my laptop.

code:
(function(){
  var start = (new Date()).getTime();
  for (var i = 0; i < 1000000; i++) {
    var a = new Array();
  }
  var end = (new Date()).getTime();
  return (end-start);
})()
returns 266 ms on my laptop.

OddObserver
Apr 3, 2009

LP0 ON FIRE posted:



About new Array() vs []: isn't defining [] mean that it's sort of immutable and new Array() mutable?

Correct.
> Array = function() { this.length = 42; }
> x = new Array
> x.length
42
> x = []
> x.length
0

[] is equivalent to the initial meaning of new Array().
(This was actually one of the clarifications in 5th edition of the spec, IIRC).

(And using new Array hence might be slower since it needs to look up the global named
Array, which may be tricky since the global scope in a web browser is nuts)

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

OddObserver posted:

[] is equivalent to the initial meaning of new Array().
(This was actually one of the clarifications in 5th edition of the spec, IIRC).

It was an errata to the 3rd edition.

fuck the ROW
Aug 29, 2008

by zen death robot
I've seen some discussion of this on stackoverflow, but is there any issue with JSON.stringifying an object that contains multidimensional arrays? Arrays of array_name[x][y] = ID for example.

Chenghiz
Feb 14, 2007

WHITE WHALE
HOLY GRAIL

gently caress the ROW posted:

I've seen some discussion of this on stackoverflow, but is there any issue with JSON.stringifying an object that contains multidimensional arrays? Arrays of array_name[x][y] = ID for example.

Not that I know of, and it's pretty easy to test in the console.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

gently caress the ROW posted:

I've seen some discussion of this on stackoverflow, but is there any issue with JSON.stringifying an object that contains multidimensional arrays? Arrays of array_name[x][y] = ID for example.

There shouldn't be any problems unless there are cyclical structures.

DholmbladRU
May 4, 2006
Looking to utlize the spiderfy which George MacKerron has developed. However I have one other requirement which is to load the map with all markers "spiderd" out by default. I can mimic this by using javascript to click on the markers, but there has to be another way by using the spiderfy code. Has anyone accomplished this?

https://github.com/jawj/OverlappingMarkerSpiderfier#overlapping-marker-spiderfier-for-google-maps-api-v3

code:
var map = new google.maps.Map(document.getElementById("map-canvas"), options);
var iw = new google.maps.InfoWindow();
var oms = new OverlappingMarkerSpiderfier(map, {keepSpiderfied: true});

http://jsfiddle.net/vFAy6/5/

PleasantDilemma
Dec 5, 2006

The Last Hope for Peace

DholmbladRU posted:

Looking to utlize the spiderfy which George MacKerron has developed. However I have one other requirement which is to load the map with all markers "spiderd" out by default. I can mimic this by using javascript to click on the markers, but there has to be another way by using the spiderfy code. Has anyone accomplished this?

I use OMS and it's pretty great but it can't be set to auto spiderfy. I've seen it come up at the project site before. This issue has a guy with an idea on how to fake it, consider trying that.

DholmbladRU
May 4, 2006

PlesantDilemma posted:

I use OMS and it's pretty great but it can't be set to auto spiderfy. I've seen it come up at the project site before. This issue has a guy with an idea on how to fake it, consider trying that.

Oh OMS is great. I just have some ridiculous requirement from this customer.. Thanks for that link:)

Pollyanna
Mar 5, 2005

Milk's on them.


I'm trying to use Select2 to select/submit multiple stock symbols at a time. I have a JSONified Python dictionary, stringified, that I can load into my HTML template. It looks something like this:

JavaScript code:
{
    "AAPL":"Apple",
    "GOOG":"Google",
    "IBM":"International Business Machines",
    etc.
}
However, I don't know how to get Select2 to use JSON that I implant into a template. Has anyone used Select2 like this?

EAT THE EGGS RICOLA
May 29, 2008

Why is each object not surrounded by curly braces? As you have it, this is one object with a giant pile of name-value pairs.

Pollyanna
Mar 5, 2005

Milk's on them.


...Oh :smith: Sorry, I'm not used to JSON. What I do at the moment is take a massive array and create an <option> tag for each element, which slows everything the gently caress down. I was hoping to use Select2's data functions to speed that up, but I may be a little lost.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Pollyanna posted:

...Oh :smith: Sorry, I'm not used to JSON. What I do at the moment is take a massive array and create an <option> tag for each element, which slows everything the gently caress down. I was hoping to use Select2's data functions to speed that up, but I may be a little lost.

In your template, assign it to a javascript variable:

code:
<script>
    var whatever = {{ stock_symbols_json }};
</script>
Then in your code that sets up the select2 control, you can just refer to your 'whatever' variable since it's in the global scope.

Adbot
ADBOT LOVES YOU

Pollyanna
Mar 5, 2005

Milk's on them.


Unfortunately, it looks like Python's "translate to JSON" dealio causes a bit of a problem: all the keys are turned to strings, when I need them to be flat-out variables. e.g.:

code:
{"text": "MHNC", "id": 4523}, {"text": "MHO", "id": 4524}, {"text": "MHO$A", "id": 4525}
should be

code:
{text: "MHNC", id: 4523}, {text: "MHO", id: 4524}, {text: "MHO$A", id: 4525}
For context, this is what Select2 expects:

code:
data:[{id:0,text:'enhancement'},{id:1,text:'bug'},{id:2,text:'duplicate'},{id:3,text:'invalid'},{id:4,text:'wontfix'}]
How do I make it so that Python doesn't output the keys as strings?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply