使用angularjs DropDownList的设置默认值? [英] Set default value for dropdownlist using angularjs?

查看:173
本文介绍了使用angularjs DropDownList的设置默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有code,它然后填充的DropDownList和获取列表中的最后一个项目的JavaScript变量。现在我想要做的就是选择最后一项为我缺少的。什么默认的?

 < D​​IV CLASS =行>
< D​​IV>
    <选择NG-的init =lastItemNG模型=congressFilterNG选项=cc.congressLongName在ccList CC>< /选择>
< / DIV>
< D​​IV CLASS =网格式数据-NG-格=userGrid>
< / DIV>

  ccResource.query(功能(数据){
    $ scope.ccList.length = 0;
    angular.forEach(数据,功能(ccData){
        $ scope.ccList.push(ccData);
    })    //为DropDownList的设置默认值?
    $ scope.lastItem = $ scope.ccList [$ scope.ccList.length - 1];
});


解决方案

您只需要在你的控制器ASIGN一个值congressFilter。

  $ scope.congressFilter ='someVal';

这要看怎么然而数据看起来有点。

I have code that populates then dropdownlist and the javascript variable that gets the last item in the list. Now all I want to do is select that last item as the default .What am I missing ?

<div class="row">
<div>
    <select ng-init="lastItem" ng-model="congressFilter" ng-options="cc.congressLongName for cc in ccList"></select>
</div>
<div class="grid-style" data-ng-grid="userGrid">
</div>

   ccResource.query(function (data) {
    $scope.ccList.length = 0;
    angular.forEach(data, function (ccData) {
        $scope.ccList.push(ccData);
    })

    //Set default value for dropdownlist?
    $scope.lastItem = $scope.ccList[$scope.ccList.length - 1];
});

解决方案

You simply need to asign a value to congressFilter in your controller.

 $scope.congressFilter = 'someVal';

It depends a little on how your data looks however.

这篇关于使用angularjs DropDownList的设置默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆