I am trying to find the index of an item in a classic asp array. i get how it's possible with looping, but is there something else i can use? indexOf() or something along those lines? i can't seem to find anything online
Is it an array of strings, or some other type of objects?
For standard data types you can use Array.BinarySearch(myArray, searchString), but you have to sort the array first.
Related
I am trying to reach to the 3rd cn Array (highlighted) in, please suggest and logic and sample code.
To solve the nested array, first see the schema of the preceding array, keep the notice of the elements and then follow the following logic to get the array exploded.
explode(preceding_array.first_lv_element.nested_array_name)
I used the below code
cn_cn_cn_arr=cn_cn_arr.select(cn_cn_arr.pid,
cn_cn_arr.id,
explode(cn_cn_arr.cn_cn.cn).alias('cn_cn_cn'))
My friends, Could you please explain the concept of these methods to me? Normally, when I get a data I would use 'index' to refer to items in a model and specify roles via data attribute. I came across 'item' method today and the explanation of this method is "Returns the item for the given row and column if one has been set; otherwise returns 0." What are differences from 'index'+'data' method? Is it just a shortcut?
This is the documentation of 'item' method.
https://doc.qt.io/qt-5/qstandarditemmodel.html#item
Alternatively, this is the documentation of 'index' method.
https://doc.qt.io/qt-5/qstandarditemmodel.html#index
I'll try my best to explain it.
The item is like the actual widget you see in the view (it's not actually a widget, but I think it's a good way to think about it). It's what the user is actually seeing.
The index is more "behind the scenes." It's like a pointer to a position in the model.
An item can exist without an index. But a valid index cannot exist without an item. The item only associates with an index when it is put into a model. Otherwise, it's just an item that no one can look at.
Take an array as an example... It contains multiple "items". You specify which item from the array you want by providing a number, aka the index. Simply put, the index only exists when it is associated with an item in the array. But the item can exist outside of the array and be it's own thing without an index.
The QModelIndex was created to be a lightweight way to reference items in a model. Similar to the way you can use a number to represent an object stored in an array.
I have been reading around and just havent found any type of answer.
I have a multiple select list and need to take the the values of the multiple select and pass them to an API call.
But I dont understand how drupal renders the multiple select list and how to habdle this.
Can someone please explain this to me or if you have come across any docs that explain this, please point me in the right direction.
Also, when I try to write the select to the db, I always get a the value 1... never changes...
Any help is appreciated :)
Solved:
The Multiple select is stored in an associative array where the key value pair are taken from the key value of the list, this means that both the key and value get the same value.
I did this by using devels dvm(); function which displays the array in the message area after the node was saved.
I have a problem with the AdvancedDataGrid widget. When the dataProvider is an ArrayCollection (of arrays), the nth array (within the collection) is also the nth row within the grid, and I can jump and display the i-th row by scripting
adg.selectedIndex = i;
adg.scrollToIndex(i);
now, when I add a Grouping, the dataProvider ends up being a GroupingCollection2, and now the index in the dataprovider's source does not correspond to the index in the adg anymore (which is understandable, because it's being grouped).
How can I select and display a row in grouped data efficiently? Currently, I have to traverse the adg and compare each found item with its data attributes in order to find the correct index of the row within the adg, and jump to it like above. This process is very slow. Any thoughts?
edited later:
We already used a caching object as Shaun suggests, but it still didn't compensate for the search times. In order to fully construct a sorting of a list of things (which this problem equates to, as the list is completely reordered by the grouping), you always have to know the entire set. In the end we didn't solve that problem. The project is over now. I will accept Shaun's answer if no one knows a better way in three days.
Depending on what values your comparing against you can store the objects in a dictionary with the lookup using the property/properties that would be searched for, this way you have a constant time look-up for the object (no need to look at every single item). Say for example your using a property called id on an object then you can create an AS object like
var idLookup:Object = {};
for(myObject in objects)
idLookup[myObject.id] = myObject;
//Say you want multiple properties
//idLookup[myObject.id]={};
//idLookup[myObject.id][myObject.otherProp] = myObject;
now say the user types in an id you go into the idLookup object at that id property and retrieve the object:
var myObject:Object = idLookup[userInput.text];
myAdg.expandItem(myObject, true);
now when you want to get an object by id you can just do
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/AdvancedDataGrid.html#expandItem()
I haven't done any thorough testing of this directly, but use a similar concept for doing quick look-ups for advanced filtering. Let me know if this helps at all or is going in the wrong direction. Also if you could clarify a bit more in terms of what types/number of values you need to lookup and if there's the possibility for multiple matches etc. I may be able to provide a better answer.
Good luck,
Shaun
Should be easy but google couldn't give me a straight answer. I have an array. The fields in the array have underscores that I would like to remove e.g. "Column_1" to "Column 1". Does anyone know a good way to do this without looping through the whole array and rebuilding it anew? I didn't see any methods in the reference that would make this easy. thx
Depending on where you are using this Array, you could use the labelFunction to format the data before presenting it. It is present in Lists, DataGrids and Trees.
But you'd only need this if you have a very large data and wouldn't want to loop over all the records before showing them. A labelFunction would "reprocess" the label everytime before it's presented.
Flex 3 has built in refactoring
Edit... I may have misunderstood..
If you want to format the data in the array just loop through it and use regex to remove the underscores... or you can modify your query which grabs the data (if it is populated from a query)