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

angularjs – 使用对象名称的Typeahead

发布时间:2020-12-17 07:42:34 所属栏目:安全 来源:网络整理
导读:我正在尝试使用 AngularJS UI Bootstrap喜欢这样: html的 input type="text" ng-model="selectedStuff" typeahead="stuff.name for stuff in stuffs | filter:$viewValue"/span{{selectedStuff.name}}/spanspan{{selectedStuff.desc}}/span .js文件 $scope.
我正在尝试使用 AngularJS& UI Bootstrap喜欢这样:

html的

<input type="text" ng-model="selectedStuff" typeahead="stuff.name for stuff in stuffs | filter:$viewValue"/>

<span>{{selectedStuff.name}}</span>
<span>{{selectedStuff.desc}}</span>

.js文件

$scope.stuffs= [
                {
                 "name":"thing1","desc":"this is the first thing"
                },{
                 "name":"thing2","desc":"this is the second thing"
                }
               ]

目前,我已经能够使用所选择的名称来更新模型,但是我的目标是通过类型头传递整个对象.有没有干净的方式来做这个只使用输入?

当然的事:-)

来自http://angular-ui.github.io/bootstrap/的typahead指令使用与AngularJS select directive相同的超灵活语法,用于ng选项.所以你可以写:

typeahead="stuff as stuff.name for stuff in stuffs | filter:$viewValue"

这是一个工作的朋友:http://plnkr.co/edit/5kGZkNPZ7rIFfb4Rvxej?p=preview

(编辑:李大同)

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

    推荐文章
      热点阅读