0
我正在处理angularjs应用程序,并且作为一个新手面临许多问题。我有两个角度的UI网格。基于文本字段中的用户输入,它必须在UI网格中显示值。有艰难的时间来实现这一点。任何的意见都将会有帮助。 请查看我的代码here的演示。根据用户输入显示角度UI网格和值
当用户类型/选择亚特兰大从为文本字段文本字段和芝加哥和SearchLocations点击按钮,它显示与名义下AtlantaChicago显示值的网格。就像明智的用户输入NewYork和芝加哥一样,它必须显示以名字NewYorkChicago显示的网格值。当文本框中没有输入值时,不应显示网格。任何建议都会非常有帮助。
HTML代码:
<body style="padding-left:15px" ng-controller="searchController">
<form class="form-inline">
<div class="row">
<div class="form-group" ng-controller="citiesCtrl">
<label>From</label>
<input type="text" ng-model="places1" placeholder="Type Departure City" typeahead="item for item in items | filter:$viewValue | limitTo:8">
</div>
<div class="form-group" ng-controller="citiesCtrl">
<label>To</label>
<input type="text" ng-model="places2" placeholder="Type Destination City" typeahead="item for item in items | filter:$viewValue | limitTo:8">
</div>
</div>
<input type="submit" value="SearchLocations" ng-submit="submit()">
<div ng-repeat="user in users">
<h3>{{user.name}}</h3>
<div ui-grid="{ data: user.details }" ng-show="user.show" class="myGrid"></div>
</div>
</form>
</body>
JS代码:
angular.module('myApp', ['ngAnimate', 'ui.bootstrap','ngTouch', 'ui.grid', 'ui.grid.selection', 'ui.grid.edit','ui.grid.cellNav']);
angular.module('myApp').controller('citiesCtrl',function($scope){
$scope. places = undefined;
$scope.items = ["Atlanta", "Chicago", "NewYork"];
$scope.selectAction = function() {
console.log($scope.places1);
};
});
/*Controller for searchLocations button*/
angular.module('myApp').controller('searchController', ['$scope', function($scope) {
$scope.submit = function() {
alert("in submit");
if ($scope.places1) {
alert("inside the condition");
/* $scope.list.push(this.places1);
$scope.places1 = '';
*/ }
};
$scope.users = [
{'name' : 'AtlantaChicago',
'show' : true,
'details' : [
{"Travel Date": "10/10/2014", commute:"Bus"},
{"Travel Date": "10/11/2014", commute:"flight"}]
},
{'name' : 'NewYorkChicago',
'show' : true,
'details': [
{"Travel Date": "3/15/2016", commute:"flight"},
{"Travel Date": "10/12/2016", commute:"flight"},
]
}
];
$scope.gridOptions = {
enableFiltering: true,
columnDefs: [
{ name: 'Travel Date', width: '5%'},
{ name: 'Departurecommute', enableFiltering: false, width: '12%' }
],
rowHeight: 20,
enableHorizontalScrollbar:2
};
}]);