【问题标题】:Show values in another tag using values in dropdown - firebase-database使用下拉列表中的值显示另一个标签中的值 - firebase-database
【发布时间】:2018-02-26 18:29:29
【问题描述】:

我正在尝试通过下拉选项使用设备(父节点)生成系统值(子节点)。因此,当我从下拉列表中选择任何设备值时,它也应该根据所选设备更改系统的值。我的 Firebase 中的 JSON 文件包含在下面。

HTML

<div class="form-group col-xs-6 col-sm-6 col-md-6 col-lg-6" id="equipList">
    <label for="selectequ">Select Equipment</label>
    <select class="form-control" id="selectequ" data-ng-model="equipment">
        <option value="" disabled="" selected="" style="display: none">Select Equipment</option>
        <option data-ng-repeat="eq in add track by $index">{{eq.$id}}</option>
    </select>
    <p data-ng-model="system"></p>
</div>

JSON

{
  "7889" : {
    "description" : "789",
    "group" : "Mechanical",
    "system" : "789"
  },
  "asd" : {
    "description" : "asd",
    "group" : "Mechanical",
    "system" : "asdf"
  }
}

【问题讨论】:

    标签: html angularjs json firebase firebase-realtime-database


    【解决方案1】:

    这就是你所追求的吗?

    <div class="form-group col-xs-6 col-sm-6 col-md-6 col-lg-6" id="equipList">
        <label for="selectequ">Select Equipment</label>
        <select class="form-control" id="selectequ" data-ng-model="equipment">
            <option value="" disabled="" selected="" style="display: none">Select Equipment</option>
            <option data-ng-repeat="eq in add track by $index" value="$index">{{eqData.description}}</option>
        </select>
        <p data-ng-model="add[equipment].system"></p>
    </div>
    

    编辑:将option 值设置为 $index。使用select 设备 值作为add 的索引并检索system

    【讨论】:

    • 'equipment.system'在我选择设备时没有打印出系统
    • 抱歉,Angular 版本搞混了。查看编辑。
    • 我对 value="{{eqName}}" 做了一些更改。之后,该值只获取0或1等索引。但它是显示系统以及传递索引而不是设备名称。如何传递值 ($id) 而不是索引?
    • eqName 应该显示值“7889”、“asd”等。我已将 {{eq.$id}} 更新为 {{eqName}}
    • 我已通过插入从我的 firebase 数据库中检索到的数据图像来更新问题。如您所见,它具有索引值,但是当我编写 eqData.$id 它显示设备值但 eqName 正在生成索引值!
    猜你喜欢
    • 2016-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-14
    • 2018-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多