【问题标题】:Flex datagrid not updated properlyFlex 数据网格未正确更新
【发布时间】:2011-10-08 08:49:25
【问题描述】:

我有两个表: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 结果处理程序中缺少某些内容。 Google 没有提供太多帮助。

   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)。

【问题讨论】:

    标签: apache-flex refresh flex-datagrid


    【解决方案1】:

    我认为您需要设置您的 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);
        }
    }
    

    【讨论】:

    • 您使用的是什么版本的 Flex SDK?我正在使用适用于 PHP 4.5 的 Flash Builder,但在 dropDownList 组件的内容辅助菜单 (Ctrl+Space) 中没有获得 .selectedLabel。
    • 更新了 4.5 下拉菜单而不是组合框。试一试,让我知道。 :)
    • 我注意到这“可能”不起作用,但在发表评论之前,我试了一下。请注意,deptName 不是 Person 类的成员。也就是说,Person 表中没有 deptName 字段。我们只有 deptID 字段。此外,由于我的 INNER JOIN 语句,我得到了数据网格字段 deptID 下的部门名称。从我的问题中的 SQL 语句中,我清楚地得到了部门.deptName 但 FB 数据网格没有看到它。它只是将结果放在 deptID 下。诡异的。有什么线索吗?
    • 好的,所以在数据网格中,您没有部门名称列?我认为我们只是对这里的目标感到困惑。您可以粘贴显示数据网格或图像中显示的内容的源吗?
    • 内特!当我将 getPeople() 拖到它上面时,我明白为什么我的数据网格中没有 deptName 。那是因为我创建了定义了 Person 类/对象签名的库文件 Person.php。在浏览示例源代码时,我注意到有人使用了 PHP 的通用 stdClass 对象。在我的 getPeople() 函数中,我将行 $row = new Person() 更改为 $row = new stdClass();然后我不得不在 FB 中删除并重新创建 PHP 服务(刷新没有成功)和宾果游戏,我可以得到 person.deptID、person.deptName!谢谢!! StackOverflow 很棒。
    【解决方案2】:

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

    【讨论】:

    • 我同意。您是否知道通过使用新添加项的 ID 运行 SELECT 语句来仅刷新数据网格的一行?
    • 我创建了一个通过 ID 获取人员详细信息的函数。
    • @shailenTJ 我会说你在应用程序初始化期间加载了所有部门集合,之后你总是可以通过 id 找到部门名称而无需返回服务器,从而节省了到后端的往返时间。
    • 我可以在 appinit() 上加载 Department 集合,方法是调用执行 SELECT * FROM Departments 的函数 getAllDepartments()。但是,这将如何帮助对数据网格进行适当的更新?基本上,createPerson 函数确实将部门的 ID 发送到服务器,但数据网格应该在 deptID 列中显示 deptName。这实际上有点令人困惑。在我的 library/Person.php 中,我没有定义 deptID 的数据类型。创建数据网格时,由于 INNER JOIN,列 deptID 显示 deptNames。
    • 我可以把我的示例 FB 项目发给你吗?如果是,我该怎么做?
    猜你喜欢
    • 2014-09-29
    • 2014-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-02
    • 1970-01-01
    • 1970-01-01
    • 2016-08-23
    相关资源
    最近更新 更多