简体   繁体   English

通过单击链接从数据库加载

[英]Load from database by clicking on a link

Using AngularJS functionality, I query objects (each having a 'number' field) in a database 使用AngularJS功能,我可以查询数据库中的对象(每个对象都有一个“数字”字段)

<article class='recipe' ng-cloak ng-repeat='recipe in recipes'>
  <h2>
     <a data-ng-bind="recipe.number"></a>
  </h2>
</article>

that displays a list of 'recipe.number': 显示“ recipe.number”的列表:

 d024b8f1-a278-401d-9fd5-a72458a42dd8
 0f647d45-607c-40a7-8dae-daea7385ea3f
 49580ae2-54ea-491a-89ad-7035a8e10e0e
 ...

Could you please advise me - how can I, by clicking on the displayed numbers, display another object's field (eg 'recipe.text')? 您能否建议我-如何通过单击显示的数字显示另一个对象的字段(例如'recipe.text')? Thank you. 谢谢。

You can do something like the following : 您可以执行以下操作:

<article class='recipe' ng-cloak ng-repeat='recipe in recipes'>
  <h2>
    <a data-ng-bind="recipe.number" ng-click="showDetails = ! showDetails"></a>
  </h2>
  <div ng-show="showDetails">
    <p>{{recipe.text}}</p>
  </div>
</article>

When you click on the number you show the details and when you click one more time it hides the details. 当您单击该数字时,将显示详细信息;当您再次单击该数字时,它将隐藏该详细信息。

Is this you want? 这是你想要的吗?

<article class='recipe' ng-cloak ng-repeat='recipe in recipes'>
  <h2>
     <a data-ng-bind="recipe.number">{{recipe.text}}</a>
  </h2>
</article>

Building on Lotus91's answer: If you want to show one recipe at a time: 以Lotus91的答案为基础:如果您想一次显示一个食谱:

<article class='recipe' ng-cloak ng-repeat='recipe in recipes'>
  <h2>
    <a data-ng-bind="recipe.number" ng-click="showRecipe = recipe.text"></a>
  </h2>
</article>

<div ng-if="showRecipe != ''">
  <p>{{showRecipe}}</p>
</div>

OR, if you want to show more than one at a time: 或者,如果您想一次显示多个:

<article class='recipe' ng-cloak ng-repeat='recipe in recipes'>
  <h2>
    <a data-ng-bind="recipe.number" ng-click="recipe.showRecipe = ! recipe.showRecipe"></a>
  </h2>
  <div ng-if="recipe.showRecipe">
    {{recipe.text}}
  </div>
</article>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM