AngularJS选择选项文本

时间:2018-01-06 16:49:11

标签: angularjs html-select ng-options

我有一个表单来更新我的页面。页面有其父页面,我想有一个组合框,我可以在其中选择当前页面的另一个父页面。加载页面后,我在组合框中看不到当前页面的父级标题。当我打开组合框时,我可以看到所有页面的所有标题。

Page.java

public class Page {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    private Long id;

    @Column(name = "title")
    private String title;

    @Nullable
    @ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    private Page parentPage;

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "parentPage")
    private List<Page> childPages;

    /* other fields, constructors, getters and setters for all the fields... */
}

editPage.html

<div ng-controller="EditPageController">
  <form>
    ...
    <label>Parent page: </label>
    <select ng-model="currentPage.parentPage" ng-options="page.title for page in allPages"></select>
    ...
  </form>
</div>

edit-page-controller.js

app.controller('EditPageController', ['$scope', '$routeParams', 'PageService',
    function ($scope, $routeParams, PageService) {
        var pageId = $routeParams.pageId;
        PageService.getPageById(pageId, function (response) {
            $scope.currentPage = response.data;
            console.dir($scope.currentPage);
        });

        PageService.getAllPages(function (response) {
            $scope.allPages = response.data;
            console.dir($scope.allPages);
        });
        ...
    }
]);

我的方法getPageById正确地抓取页面,getAllPages正确地返回所有现有页面,正如我在控制台中看到的那样。我应该怎么做才能在组合框中看到我当前父母的头衔?

0 个答案:

没有答案