开发者

How can I check to see if an item already exists in my data provider in flex 4?

I have a dataProvider and there is an object in the dataProvider. I want to know if there is a way to see if you can check to see if part of the object exists. So lets say I have an object with usernames and passwords and I want to add a username to that dataProvider. How can I go by checking t开发者_运维问答o see the username is not already there?


Normally I would make this kind of a check against my back end database directly instead of against the data I've already got loaded in my application. It's entirely possible data has changed since got loaded into the app.

However, to go back and answer your question, you could do this a couple of ways.

Create a filter and filter your ArrayCollection by the username you're looking for. If the ArrayCollection length is 0 after you've filtered it, the username doesn't exist.

or

Use a traditional for each loop to go through the ArrayCollection and look for the username.

for each (var o:Object in myArrayCollection)
{
  if (o.userName == theUsernameImLookingFor)
  {
     usernameExists = true;
     break;
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜