Flex ArrayCollection getItemIndex always -1 - apache-flex

I have a question, why doesn't this work?
I have an ArrayCollection with data; a trace of random index of this using
ObjUtil.toString(arrc.getItemAt(index))
gives me
(Object)#0
label = "VALUE"
value = 20
I then create an object:
var newObj:Object = new Object()
newObj.label = "VALUE"
newObj.value = 20
A trace of this gives:
(Object)#0
label = "VALUE"
value = 20
Now I do:
arrc.getItemIndex(newObj)
and it always gives me -1.
Does anyone know where I'm going wrong?

Just a bit of clarification.. You're not actually adding that object to the collection? You're creating an object that is the same as an object in the collection and using it to get the index?
The newObj is not the same as the object in the arraycollection.. they just have the same values. The getItemIndex method will only 'find' an object if it's actually the same object (it's not going to drill down and compare member variables).

getItemIndex is searching for the same item (instance) and not for an equal item with equal property values.

Related

how can i get value from database into dropdown list?

dropdown list was automatically generating number sequence. after selecting value from the database it showing same as the auto generated dropdown list
e ddlDuration.DataSource = Enumerable.Range(1, 100);
ddlDuration.DataBind();
ddlDuration.Items.Insert(0, new ListItem("--Select Customer--", "0"));
this code I used for generating numbers.
ddlDuration.SelectedIndex = ddlDuration.Items.IndexOf(ddlDuration.Items.FindByValue(oList[0].Duration));
and this for reading data from the list. the value can get till the
oList[0].Duration.
Hi Raheez,
It may be happening because the value of oList[0].Duration is not in 1-100 range.
Or
Try this :
ddlDuration.SelectedIndex = ddlDuration.Items.IndexOf(ddlDuration.Items.FindByValue(oList[1].Duration.Trim()));

Get ObjectID in mongolite R library

I can successfully retrieve data from my mongoDB instance but need to re-use the objectID for a depending query.
The following code seems to get my entire object but NOT the id. What am I missing?
# Perform a query and retrieve data
mongoOBj <- m$find('{"em": "test#test.com"}')
I realise this is an old question and OP has probably figured it out by now, but I think the answer should be
mongoOBj <- m$find(query = '{"em": "test#test.com"}', field = '{}')
instead of
mongoOBj <- m$find(query = '{"em": "test#test.com"}', field = '{"_id": 1}')
In the second case, the result will be a data frame containing ONLY the IDs. The first line will result in a data frame containing the queried data, including the IDs.
By default, field = '{"_id": 0}', meaning _id is not part of the output.
If you look at the documentation you see that the find method takes a field argument, where you specify the fields you want:
find(query = ’{}’, fields = ’{"_id" : 0}’, sort = ’{}’, skip = 0, limit = 0, handler = NULL, pagesize = NULL)
So in your case it will be something like
mongoOBj <- m$find(query = '{"em": "test#test.com"}', field = '{"_id": 1}')
FYI So the easiest way to get all fields is to do the query with field="{}". That will overwrite the default in the mongolite:: package find() arguments list.
It was driving me nuts for a little while too.

How to select specific index in a multidimensional array in asp.net using vb

I cannot explain well in the title so i'll explain here the scenario:
In here, i have a query that will be placed in an array.
Dim arrUsers As Object = {{sqlReader("dephead"), dropdown1}, {sqlReader("mm"), dropdown2}
I want to enable the dropdown object if it matches my if else condition:
'indexes1= the 1st indexes of each pair in the array (the sqlReaders)
'indexes2= my dropdown objects in my user control
For Each indexes1 In arrUsers
If Session.Item("EmployeeID") = indexes1 Then
indexes2.Enabled = True
End If
Next
so lets say the my session id will be "dephead", then the dropdown1 will be enabled. Thats what i would like to happen but im not familiar on arrays so kindly help me. Thanks.
This should work:
For i As Integer = 0 to arrUsers.GetUpperBound(0)
If Session.Item("EmployeeID") = arrUsers(i)(0) Then
arrUsers(i)(1).Enabled = True
End If
Next
You simply give the array two indexes instead of one. arrUsers(0)(1), for example. The first index returns the object at that index, and the second index returns the object inside the previously returned array. arrUsers(0)(1) will first grab the array at 0 index ({sqlReader("dephead"), dropdown1}), then get the object at index 1 (dropdown1).
This answered my question. The answer above helped me and i just changed the declaration of my arrays and changed some syntax.
Dim arrUsers(,) As Object =
New Object(,) {
{sqlReader("dephead"), dropdown1}, _
{sqlReader("mm"), dropdown2}, _
}
Dim bound0 As Integer = arrUsers.GetUpperBound(0)
Dim bound1 As Integer = arrUsers.GetUpperBound(1)
For i As Integer = 0 To bound0
If Session.Item("EmployeeID") = arrUsers(i, 0) Then
arrUsers(i, 1).Enabled = True
End If
Next

how to fix EntityReference error

I'm attempt to commit mostly all new objects to the database, apart from the user. I'm new to entity framework and im not sure how to combat this error.
Error on line _orderDetail.CalenderItems.Add(_newCalendarItem):
The object could not be added or attached because its EntityReference has an EntityKey property value that does not match the EntityKey for this object.
Code:
_db.Orders.AddObject(_order)
For Each n In _namelist
_db.Names.AddObject(n)
Next
For Each n In _namelist
For i As Integer = 1 To _copies
Dim _orderDetail As New OrderDetail
_db.OrderDetails.AddObject(_orderDetail)
_orderDetail.Name = n
_orderDetail.Order = _order
For Each c In _calendarItems
Dim _newCalendarItem As New CalenderItem
_newCalendarItem.Image = c.Image
_newCalendarItem.YearMonth = c.YearMonth
_orderDetail.CalenderItems.Add(_newCalendarItem)
Next
Next
Next
_db.SaveChanges()
I believe I need to add add an entity reference but I'm not sure how. Can anyone point me in the right direction
As dnndeveloper says, your answer is ObjectContext.CreateObject<T>.
So you're gonna want -
Dim ci = _db.CreateObject(Of CalenderItem)()
ci.OrderDetail = _orderDetail
ci.Image = c.image
ci.YearMonth = c.YearMonth
_orderDetail.CalenderItems.Add(ci)
or something along those lines. I've run into this issue a couple of times and this has worked so far.
HTH
Instead of creating a "new calendaritem" you should use _db.OrderDetails.CalendarItem.New() etc... either that or set _newCalendarItem.EntityKey to null.

Flex DropDownList LabelFunction Issue

I have a dropdown list as :
<s:DropDownList id="cad" width="100%" dataProvider="{model.referenceList.refPatientResponseLists}"
labelFunction="myFunction" selectedIndex="{model.cd.code}"/>
Now the refPatientResponseLists returns 3 rows of data & I need to display the 3 values in the Dropdownlist. So I have the label function as :
public function myFunction(item:Object):String {
return item['refPatientResponses'] [cad.dataProvider.getItemIndex(item)]['responseDesc']+'';
}
But this displays only 1 value in the Dropdownlist. So it returns something like:
return item['refPatientResponses'] [0] ['responseDesc']+''
How can I get all the 3 values in the dropdown. Hope my question is understandable and expecting a reply.
Thanks
Harish
Object structure from the logs:
(Typed Object #1 'datacollection.model.ReferenceList')
(Array #3)
refPatientResponseLists = (Externalizable Object #4 'flex.messaging.io.ArrayCollection')
(Array #5)
[0] = (Typed Object #6 'datacollection.model.RefPatientResponseList')
refPatientResponses = (Externalizable Object #7 'flex.messaging.io.ArrayCollection')
(Array #8)
[0] = (Typed Object #9 'datacollection.model.RefPatientResponse')
responseSequence = 1
responseDesc = "No"
responseCode = 28
responseTypeCode = 10
[1] = (Typed Object #10 'datacollection.model.RefPatientResponse')
responseSequence = 2
responseDesc = "Yes"
responseCode = 29
responseTypeCode = 10
[2] = (Typed Object #11 'datacollection.model.RefPatientResponse')
responseSequence = 3
responseDesc = "Claim Not Found"
responseCode = 30
responseTypeCode = 10
I'm unclear if your issue is that your drop down list only has a single item or that all items in the drop down list are displaying the same text; but I wrote this answer assuming the former.
Did you run in debug mode? How many times is the labelFunction being called? I think the labelFunction is a red herring in this case. If the list only shows a single item, it is most likely because it thinks the dataProvider only has a single item.
The labelFunction should be called 3 times if you have a dataProvider w/ three items. It is called once for each item.
Generally, my binding experience is most consistent if I do not bind into multiple objects. So, you this would be okay:
model.referenceList
or this
referenceList.refPatientResponseLists
But, I would not expect this to work:
model.referenceList.refPatientResponseLists
So, the question I have is are you sure that three items are being returned in the dataProvider? Are you sure that the component knows that three items are in your dataProvider (AKA Is Binding properly updating)?
Without knowing your object structure, it is hard to debug your labelFunction, but you shouldn't need to use the getItemIndex function.
Ok I was able to solve it using
Model.referenceList.refPatientResponseLists.getItemAt(0).refPatientResponses
Maybe helpful for others who have similar issues :)

Resources