【问题标题】:Displaying details based on selected radio button根据选定的单选按钮显示详细信息
【发布时间】:2016-10-28 12:45:01
【问题描述】:
$scope.units.push({
  id: response[j]["productId"],
  itemPrice: response[j].productPrice,
  discountPrice: response[j].discountPrice,
  productUnit: response[j].productUnit
});

我有单位数组。它包含 id、itemprice..fields 和数据。 我正在显示基于 productunits 的单选按钮。 (我的意思是 productunit 的数量等于单选按钮的数量)。如果我选择单选按钮,那么我想显示特定的 itemprice,discountprice。 如何实现?

【问题讨论】:

  • 如何显示单选按钮?
  • 更新相同的帖子。并使您的问题更有意义。

标签: javascript angularjs json ionic-framework


【解决方案1】:

好吧,您将选定的项目分配给一个名为 selectedPerson 到 ng-model 的范围变量。因此,您可以简单地打印ng-repeat 范围之外的数据。比如:

<p ng-repeat="item in units ">
    <label>
        <input type="radio" name="item" ng-model="selectedPerson" ng-value="item"/>
        {{item.productUnit}}
    </label>
</p>
<p>{{selectedPerson.itemPrice}} {{selectedPerson.discountPrice}}</p>

重要提示:不要忘记在您的控制器中初始化$scope.selectedPerson = {},以便selectedPerson 属于您的控制器范围,而不是ng-repeat 的范围。

【讨论】:

  • 感谢 lucasnadalutti 的快速响应。我会试试这个。
  • 抱歉,我忘记在input 中添加内容了。请查看更新的答案。
  • 感谢卢卡斯纳达卢蒂。我会试试的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-04-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多