0

使用以下 json 集合:

 $scope.searchscope = [

{ id: 0, name: "Base", description: "Search only the specified base object. The value is equal to 0." },
{ id: 1, name: "OneLevel", description: "Search the child objects of the base object, but not the base object itself.The value is equal to 1" },
{ id: 2, name: "Subtree", description: "Search the base object and all child objects. The value is equal to 2" }
];

和以下标记

 <select data-ng-model="mySelections[0].SearchFilterMembershipsScope" data-ng-options="i.id as i.name for i in searchscope" data-ng-required="true"></select>

我已经成功生成了一个带有 3 个选项的选择。显示当前选定项目“描述”的工具提示的最佳角度方式是什么?在用户导航下拉菜单时也可以这样做,即做出选择,诗句实际上已经做出了选择?

4

2 回答 2

1

你需要一张来自id→的地图description。填充它的一种方法是:

$scope.idToDescription = null;

$scope.$watch("searchscope", function(newval) {
    if( newval != null ) {
        $scope.idToDescription = {};
        var i;
        for( i=0; i < newval.length; i++ ) {
            $scope.idToDescription[newval[i].id] = newval[i].description;
        }
    }
});

并在您的模板中将其用作:

<select ... 
    title="{{ idToDescription[mySelections[0].SearchFilterMembershipsScope] }}">
于 2013-10-30T10:34:03.080 回答
0

如果您正在使用 Twitter Bootstrap,您还可以考虑查看 UI Bootstrap中的工具提示,如果您想要更高级的选择框,请考虑使用基于Select2的ui-select2

于 2013-11-06T16:35:03.230 回答