我正在使用我的角度雞尾酒應用程序,並設法進入顯示我的數據庫中所有雞尾酒(僅顯示名稱)的部分,但現在我想如果我點擊某個雞尾酒以在特定的div中顯示完整內容。點擊在div上顯示特定查詢
我可以用ng-click做點嗎?
我目前的HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Bar Master</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!--ANGULAR-->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="js/controller.js"></script>
<!--CSS-->
<link rel="stylesheet" type="text/css" href="style.css"></link>
<!--Yanone font-->
<link href="https://fonts.googleapis.com/css?family=Yanone+Kaffeesatz" rel="stylesheet">
<!--Font Awesome-->
<link rel="stylesheet" href="font-awesome/css/font-awesome.min.css">
</head>
<body ng-app="mainApp">
<div ng-controller="cocktail">
<div class="container cocktail_list">
<div class="col-sm-12">
<center><h2>COCKTAILS THAT WE SERVE</h2></center>
</div>
<div class="col-sm-8">
<ul>
<div class="col-sm-3" ng-repeat="drink in cocktails | filter:globalSearch">
<li>
</i><button class="cocktail_button">{{" " + drink.Name + " "}}</button>
</li>
</div>
</ul>
</div>
<div id="recipe" class="col-sm-4 cocktail_image">
COCKTAIL NAME AND INGREDIENTS....
</div>
</div>
</div>
<div class="container">
<div class="col-sm-12">
<center>
<div id="seachBoxes">
<h2>Search for a cocktail by its name or ingredient</h2>
<input type="text" ng-model="globalSearch.$" class="global_search">
</div>
</center>
</div>
</div>
</body>
</html>
controller.js:
var fileX={
"records": [
{
"Name":"Martini",
"Price":"7",
"Ingredients":"Lemon peel vodka gin"
},
{
"Name":"Autumn Leaves",
"Price":"9",
"Ingredients":"gin vermouth lemon peel"
},
{
"Name":"7 Naranja",
"Price":"7",
"Ingredients":"Havana Club Añejo ice cube Apricot Brandy Angostur"
},
{
"Name":"A Day At The Beach",
"Price":"6",
"Ingredients":"malibu rum amaretto orange juice grenadine"
},
{
"Name":"Appletini",
"Price":"7",
"Ingredients":"De Kuyper Sour Apple Absolut vodka"
},
{
"Name":"B-52",
"Price":"7",
"Ingredients":"Kahlue (coffee liqour) Irish cream liqueur (Baileys) Premium Orange Liqueur"
},
{
"Name":"Black Sunset",
"Price":"8",
"Ingredients":"Malibu Black orange juice Cranberry juice "
},
{
"Name":"Blue Lagoon",
"Price":"5",
"Ingredients":"ananas juice Havana Club 3 Años rum DeKuyper Blue Curaçaa"
},
{
"Name":"Hollywood",
"Price":"7",
"Ingredients":"Absolut vodke DeKuyper Raspberry ananas juice"
},
{
"Name":"Red Splash",
"Price":"8",
"Ingredients":"tequilla red wine Graffigna Centenario Malbec agave juice lemon or lime juice grapefruit soda"
},
{
"Name":"Rum Cola",
"Price":"7",
"Ingredients":"Havana Club 3 Años rum Coca-Cola lemon lime slice"
},
{
"Name":"The Godfather",
"Price":"7",
"Ingredients":"whiskey amaretto"
},
]
}
var app = angular.module('mainApp', []);
app.controller('cocktail', function($scope){
$scope.cocktails = fileX.records;
});
所以我想請單擊代表一個特定的雞尾酒按鈕和顯示DIV與coctail的全部內容id'recipe'。又名顯示:所選雞尾酒的{{「」+ drink.Name +「」drink.Ingredients +「」}}}。
2分鐘打敗我。這是[我的版本的同一個想法](http://jsfiddle.net/g642su0v/)。 –
非常感謝,剛剛還有1個問題,我如何獲得更好/更清晰的數據顯示?代替{「姓名」:「秋葉」,「價格」:「9」,「配料」:「杜松子酒檸檬皮」},類似於Autumb葉片杜松子酒檸檬皮? – mheonyae
啊,我在@Alex K解決方案中看到了,謝謝你們兩位! – mheonyae