11
在这里,我创建了自动完成,这是工作的罚款样品,我需要做一些修改,对this.currently它的工作原理是这样如何在angularJS中将网格自动完成下拉?
,但我究竟需要的是我需要显示的下拉列表网格视图。有些喜欢上了这本
可以任何一项帮助吗?.. 感谢
var app = angular.module('app', ['ui.bootstrap']);
app.controller('TypeaheadCtrl', function ($scope, $http, limitToFilter, filterFilter) {
$scope.sample_data = [{
"name": "Nelson",
"designation":"Senior Developer",
"company": "acme",
"companydisplay": "abc"
},
{
"name": "suresh",
"designation":"Developer",
"company": "acme",
"companydisplay": "def"
},
{
"name": "Naresh",
"designation":"Developer",
"company": "acme",
"companydisplay": "xyz"
}];
$scope.filtered_sample_data = function (search) {
var filtered = filterFilter($scope.sample_data, search);
var results = _(filtered)
.groupBy('company')
.map(function (g) {
g[0].initial = true; // the first item in each group
return g;
})
.flatten()
.value();
return results;
};
});
body {
font-family:'Trebuchet MS', Verdana, sans-serif;
margin:20px 0px;
padding:0px;
text-align:center;
}
.dropdown-menu > .active > a, .dropdown-menu > .active > a:hover, .dropdown-menu > .active > a:focus {
cursor:pointer;
}
label {
cursor:default;
margin:0;
}
.form {
width:400px;
margin:0px auto;
text-align:left;
background:#F2F1F0;
border-top-left-radius: 10px 5px;
border-top-right-radius: 10px 5px;
border:1px solid #474641;
}
.formHeader {
background:#474641;
color:#ddd;
padding:4px;
font-weight:600;
border-top-left-radius: 10px 5px;
border-top-right-radius: 10px 5px;
}
.formBody {
padding:10px;
}
.data {
margin:0px auto;
text-align:left;
}
.dropdown-menu {
text-align:left;
}
table {
border-collapse: collapse;
width: 100%;
}
th{
background-color: #29ABE2;
color: white;
}
tr> td {
text-align: left;
}
th, td {
padding: 15px;
}
tbody>tr:hover {
background-color: #0088cc;
color: white;
}
.headerSortUp {
background: url(http://tablesorter.com/themes/blue/bg.gif) no-repeat 99%;
}
.headerSortDown {
background: url(data:image/gif;
base64, R0lGODlhFQAEAIAAACMtMP///yH5BAEAAAEALAAAAAAVAAQAAAINjI8Bya2wnINUMopZAQA7) no-repeat 99%;
}
.suggestion-name { min-width: 100px; }
.suggestion-designation { min-width: 100px; }
.suggestion-company { min-width: 100px; }
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.6.0.js"></script>
<link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css" rel="stylesheet"/>
<link href="http://getbootstrap.com/2.3.2/assets/css/bootstrap.css" rel="stylesheet"/>
<script src="http://getbootstrap.com/2.3.2/assets/js/bootstrap-dropdown.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.js"></script>
<div ng-app="app">
<div class='container-fluid' ng-controller="TypeaheadCtrl">
<!-- <pre>Model: {{result | json}}</pre>
<input type="text" ng-model="result" typeahead="suggestion for suggestion in cities($viewValue)">
--> <pre>Model: {{monkey | json}}</pre>
<input type="text" ng-model="monkey" typeahead-template-url="columnTwo.html" typeahead="suggestion.name for suggestion in filtered_sample_data($viewValue) | filter: $viewValue">
</div>
<!-- CACHE FILE: columnTwo.html -->
<script type="text/ng-template" id="columnTwo.html">
<table class="">
<thead ng-if="match.model.initial">
<tr>
<th>Name</th>
<th>Designation</th>
<th>Company</th>
</tr>
</thead>
<tr>
<td class="suggestion-name">
<div ng-mouseenter="selectActive($index)" ng-click="selectMatch($index)">
<a>{{ match.model.name }} </a>
</div>
</td>
<td class="suggestion-designation"> {{ match.model.designation }} </td>
<td class="suggestion-company"> {{ match.model.companydisplay }} </td>
</tr>
</table>
</script>
你错过了在columnTwo.html NG-模板结束的双引号。应该是'
即使放置它不能正常工作 –
是的,因为整个typeahead模板基本上是在你的数据中的每个建议。名称重复,我不认为你可以包含表头在模板中没有它重复每个名字。当然,您可以将“{{match.model.designation}}”放入其自己的“数据元素”中,并获得类似的效果,但不包含列标题。 –
回答
正如我评论,因为模板是在您的样本数据集重复每
suggestion.name
,它将在列出的每个名称上包含列标题。UPDATE:一个陪审团操纵的解决方案,为this previous SO answer发现,是注入角的filterFilter和,而不是使用
$scope.sample_data
作为您的收藏重复过,而不是创建一个基于$ viewValue预过滤组。为了将数据集中的所有人分组在一起,我为每个人添加了一个公司财产(在此作出假设)。然后,您可以在筛选数据集的第一个元素上设置指标属性(在此例中为initial = true
)。最后,在你的模板,除了你的
typeahead
属性值更改为suggestion.name for suggestion in filtered_sample_data($viewValue) | filter: $viewValue">
,您将设置在表头的ng-if
显示只有`match.model.initial”是真实的。只要数据集中的每个人都拥有一些与集合中所有其他人具有相同价值的通用属性,并且您按该属性进行分组,那么这将工作。
[注意过滤器使用lodash的隐式链接,所以我增加了一个lodash.js脚本标记为好。对于解决办法
信用@runTarm。
来源
2016-01-22 05:51:05
这个很好,但我确实需要的是我已经在第二张图片 –
中提到,我需要 –
@SureshB,它现在正在工作。 –
来源
2016-02-18 13:24:12 Nelson
相关问题