This question already has answers here:
What does $(selector)[0] mean in jQuery?
(4 answers)
Closed 5 years ago.
I have a button called search, when I click it it will make an AJAX request and it will fetch me some data,
How can I write an event handler function that will run when AJAX is loaded completely? i.e For example once all the search result is displayed I need to do something in that handler function.
This is just accessing an array (or an object) by index (or key). Nothing specific to jQuery.
In your case, you get a list of DOM elements from your selector, so [0] gives you the first one.
Related
We are encountering a rather strange phenomena with .map in our React-Native (version 0.59.3) project: The APK runs well on various physical devices or emulators, but not on Android Version 9.0 where it crashes with
TypeError: o.map is not a function.
(In 'o.map(function(t,n){n.icon_color=A.white,
-1!==s.findIndex(function(n){return t.title==n.title})
&&(t.icon_color=A.red)})','o.map' is undefined)
This is how the error popup looks like:
We understand that this message appears if the variable on which we are applying .map is not an array, but we do indeed make sure that it is (and anyhow it works on various other versions and devices). What are we missing here?
Some background for the curious
We have two arrays, one is an array of data sets we obtain from an API response, and the other one is a list of bookmarked data sets from a local DB on the device. We apply the map functionality on the API response array and check if a certain item from the data set is present in the database of favorites. Based on this, we change the color of the icon. According to our tester, he did also have internet access, but we anyhow monitor #react-native-community/netinfo version 2.0.0.
Related questions
Error : .map() is not a function
React .map() is not a function error
https://www.freecodecamp.org/forum/t/map-is-suddenly-not-a-function/134196
This would only happen if o is not an Array.
You can check if o is an array using
Array.isArray(o);
More details about this here. It would be safe to rule out the possibility that it is a Android 9 specific issue. I have a Android 9 device and have tested map numerous times. If you are able to consistently reproduce only on Android 9, there is a chance there is something else into play when running on it. I'd suggest checking array existence using above^ method before you run a map on it.
Other options:
If you need to change the icon color of certain elements from your array, and just need those elements, you can use .find() if for single element and .filter() for multiple elements.
If you need the entire array as response, alternatives to .map() would be .forEach() and for of loops.
Happy to update the answer with more specific answers if you can update the question with your exact code (Even if it is not reproducible on desktop browsers)
As others have said, o is not an iterable object.
You need to check higher in the stack for the problem. If o is supposed to be an array returned by an API call then it is probable that the API call has failed, or the parsing of its response has failed.
This question already has an answer here:
reactjs.net - are react-text tags required when rendered?
(1 answer)
Closed 5 years ago.
What is react-text ?
It does not exist in the code, but it appears in html after rendering
React tries to diff the minimal amount of dom it can and it needs to track the dom rendered for every child. For empty string childs it tracks it using these comment tag. So no, you cannot (and should not) remove these.
More
https://facebook.github.io/react/blog/2016/04/07/react-v15.html#no-more-extra-ltspangts
We received some amazing contributions from the community in this release, and we would like to highlight this pull request by Michael Wiencek in particular. Thanks to Michael’s work, React 15 no longer emits extra nodes around the text, making the DOM output much cleaner. This was a longstanding annoyance for React users so it’s exciting to accept this as an outside contribution.
More More
These will not appear if you do not render anything e.g. null. But for a string like (a space), these will appear.
This question already has answers here:
What does :: mean in angularJS
(3 answers)
Closed 6 years ago.
Today I was looking at some angular code and was surprised to see this operator. Not sure what this operator does? Could somebody provide more information on the special operator :: ? I have neither encountered this operator before nor seen it in AngularJS docs.
project-id="{{::vm.projectId}}"
Using that syntax will save on resources by not spawning a watcher for the variable.
When you put a variable in a template using the double-curly syntax ({{...}}) Angular will generally spawn a watcher for that variable. This means that whenever changes are made to that variable in your Angular code the front-end will reflect that change.
Sometimes this over-eager watcher syntax isn't what you want, though. For instance, you may have a variable that you know will not change, or a variable that will change, but you don't want that change reflected immediately. This is why you will sometimes see the {{::my-var}} syntax, as it doesn't spawn a watcher.
I have 2 AutoCompleteTextFields in a form (database linked). The two of them are initialized with .setText(value) and then i show the form.
Then i noticed that the filter event is fired when i initialize them and when i show the form. I don't know if this the standard behaviour or if i am doing something wrong.
Can i somehow disable this first and second filter event call?
Besides that, it throws some Java null errors too. If i take out of the form the first or the second autocompletetextfield no error is shown.
Filter is called initially to indicate that data has changed and initialize the data. You can create your own special case (e.g. first time) and do nothing there.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How does WCF deserialization instantiate objects without calling a constructor?
If I use a DataContract attribute it doesn't call my constructor, but if I skip it then it will. Why does this happen?
The purpose of serializing/deserializing is to recreate the object in its original state. The object has already been constructed so we don't need to call the constructor. It is like raising an object from the dead rather than giving birth. :)
If you need some code to happen when an object is deserialized just decorate a method with the OnDeserialized attribute and call the code you need to execute from there.