加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – md-select不能设置选定的值

发布时间:2020-12-17 07:47:28 所属栏目:安全 来源:网络整理
导读:我有一个md-select设置如下: md-select placeholder="Category" ng-model="current.Category" flex md-option ng-repeat="item in categories" ng-value="{{item}}"{{item.Name}}/md-option/md-select @ scope.categories值是 [ { "Name":"Commercial Indus
我有一个md-select设置如下:
<md-select placeholder="Category" ng-model="current.Category" flex >
    <md-option ng-repeat="item in categories" ng-value="{{item}}">{{item.Name}}</md-option>
</md-select>

@ scope.categories值是

[  
{  
  "Name":"Commercial & Industrial","ParentId":null,"Categories":[  
     {  
        "Name":"Deceptive Marketing","ParentId":19,"Categories":[  

        ],"Id":24,"ModifiedDate":"2015-08-06T07:49:53.0489545","CreatedDate":"2015-08-06T15:49:51.707"
     },{  
        "Name":"Aggressive Agents","Id":25,"ModifiedDate":"2015-08-06T07:50:10.0026497","CreatedDate":"2015-08-06T15:50:08.63"
     }
  ],"Id":19,"ModifiedDate":"08/06/2015 @ 7:49AM","CreatedDate":"08/06/2015 @ 3:49PM"
 },{  
  "Name":"Competitive Supply","Categories":[  
     {  
        "Name":"Security Deposit","ParentId":20,"Id":21,"ModifiedDate":"2015-08-06T07:49:30.3966895","CreatedDate":"2015-08-06T15:49:25.8"
     },{  
        "Name":"Meter","Id":22,"ModifiedDate":"2015-08-06T07:49:34.6571155","CreatedDate":"2015-08-06T15:49:33.3"
     },{  
        "Name":"Bill","Id":23,"ModifiedDate":"2015-08-06T07:49:41.7268224","CreatedDate":"2015-08-06T15:49:40.357"
     }
  ],"Id":20,"CreatedDate":"08/06/2015 @ 3:49PM"
   }
]

md-select工作正常.但是我无法想像的是如何设置选择值.当我尝试将模型current.Category设置为$scope.categories中的一个值时,它不会设置.

文档不明确,但您应该使用ng选择.我创造了一个 codepen来说明,但基本上是:
<md-option ng-repeat="(index,item) in categories" ng-value="{{item}}"
           ng-selected="index == 1">    
    {{item.Name}}
</md-option>

这将选择第二个类别(您的类别数组中的索引1).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读