0
我是angularjs的新手,尝试学习/找到解决方案,以便用户可以选择多个值,然后根据所选值显示不同的结果。根据用户选择的值显示不同的结果
我做了jsfiddle三个值的三个示例结果在哪里。
如果用户选择名称1,NAME1和名称1从下拉菜单然后显示从DIV类显示此结果1
而如果值是名称2,名称2和NAME2然后显示从DIV类结果展示 - 结果这2
如何实现这个?
HTML:
<div ng-controller="Main" ng-app>
<div>selections = {{selections}}</div>
<div>
<p>Select values</p>
<select ng-model="selections[0]" ng-options="i.id as i.name for i in items">
<option value=""></option>
</select>
<select ng-model="selections[1]" ng-options="i.id as i.name for i in items">
<option value=""></option>
</select>
<select ng-model="selections[2]" ng-options="i.id as i.name for i in items">
<option value=""></option>
</select>
</div>
<div class="show-this-1">3x Name1 chosen</div>
<div class="show-this-2">3x Name2 chosen</div>
<div class="show-this-3">3x Name3 chosen</div>
</div>
JS:
function Main($scope) {
$scope.selections = ["", "", ""];
$scope.sample = function() {
$scope.selections = [ "id-1", "id-2", "id-3" ];
}
$scope.items = [{
id: 'id-1',
name: 'Name 1'},
{
id: 'id-2',
name: 'Name 2'},
{
id: 'id-3',
name: 'Name 3'}];
}
你没问清楚你想要什么。你想展示什么结果? –
基本上我会推入的价值和if $ scope.selection.length == 3然后你显示div – stackg91