0

我有两个表:Person {pID, pName, deptID} 和 Departments {deptID,deptName} 像这样的 SQL 语句让我得到一个人的名字和部门的名字:

SELECT pName, departments.deptName FROM people INNER JOIN people.deptID = departments.deptID;

以上工作正常。我有一个填充了部门名称的 Flex DropDownList。当我单击提交按钮时,我能够毫无问题地获取所选部门的 ID:

protected function button_clickHandler(event:MouseEvent):void
   {
    person.pName=pNameTextInput.text;
    person.deptID=pDepartmentDropDownList.selectedItem.deptID; //ID of selected department obtained correctly.
    if (person.pID == 0)
    {
     createPersonResult.token=personService.createPerson(person);
    }
    else
    {
     updatePersonResult.token=personService.updatePerson(person);
    }
  }

我有一个 createPersonresult 处理程序,它会在添加人员时尝试更新数据网格。数据网格使用新添加的人员进行更新,但在部门列中,我从下拉列表中获取了部门的 ID。我需要重新加载 Flash 应用程序以刷新数据网格以显示部门名称。

此 createPerson 结果处理程序中缺少某些内容。谷歌没有提供太多帮助。

   protected function createPersonResult_resultHandler(event:ResultEvent):void
   {
    currentState="PeopleDetails";
    person.pID=event.result as int;
    peopleDg.dataProvider.addItem(person); //the problem might be here, more below.
    peopleDg.setSelectedIndex(peopleDg.dataProvider.getItemIndex(person));
    peopleDg.ensureCellIsVisible(peopleDg.selectedIndex);
   }

从上面的评论中,我看到添加人员确实会将人员对象的属性添加到数据网格中,除了一个属性是来自部门的外部 ID (deptID)。

4

2 回答 2

0

我怀疑的是:您上面的 select 语句仅在您第一次初始化/运行应用程序时运行。您添加后记的任何内容都无法调用使用 join 语句将部门名称带回的 select 语句,因此您只能看到 id 直到下一次加载/初始化整个应用程序。

于 2011-07-19T13:31:22.777 回答
0

我认为您需要设置您的 deptName 属性,因为当它被添加到界面中时,您没有从连接中获取它。所以像这样的事情应该可以解决我的想法吗?

编辑:对于 4.5 下拉而不是组合框

protected function button_clickHandler(event:MouseEvent):void
{
    person.pName=pNameTextInput.text;
    person.deptID=pDepartmentDropDownList.selectedItem.deptID; //ID of selected department obtained correctly.
    person.deptName = pDepartmentDropDownList.selectedItem.deptName;
    if (person.pID == 0)
    {
        createPersonResult.token=personService.createPerson(person);
    }
    else
    {
        updatePersonResult.token=personService.updatePerson(person);
    }
}
于 2011-07-19T16:34:12.870 回答