md-select angular js更新多个值

时间:2018-07-18 18:54:15

标签: angularjs angular-ngmodel md-select

这是我的代码,我正在尝试根据日期为下限和班次选择不同的值。

<div class="card whiteBckg" ng-repeat="(key, value) in requestsObj" ng-if="true">
<div class="cardHeaderDiv">
    <h4>{{key}} <span>X</span></h4>
</div>
<div class="cardBodyDiv" ng-repeat="(k, v) in value">
    <md-select ng-model="v.shift" placeholder="Select Shift" required md-no-asterisk="false">
        <md-option ng-value="tm.shiftid" ng-repeat="tm in shifts">{{ tm.shift }}</md-option>
    </md-select>

    <md-select ng-model="v.floor" placeholder="Select Floor" required md-no-asterisk="false">
        <md-option ng-value="fl.id" ng-repeat="fl in floors">{{ fl.floor }}</md-option>
    </md-select>

    <div ng-repeat="(a, b) in v.type" class="chip">
        <i class="fa fa-clock-o"></i>{{ getTotal(key, k, a) }}  {{a}}
    </div>
</div>

<div class="cardFooterDiv">
    <h4>Add more shifts for this day</h4>
</div>
</div>

$ scope.shifts = [{{shiftid:“ a”,shift:“ A”},{shiftid:“ c”,shift:“ C”},{shiftid:“ b”,shift:“ B”} ];

$ scope.floors = [{{id:“ f1”,下限:“ F1”},{id:“ f2”,下限:“ F2”},{id:“ f3”,下限:“ F3”} ];

[{     “ shift”:null,     “ floor”:null,     “类型”:typeObj },{     “ shift”:null,     “ floor”:null,     “类型”:typeObj },{     “ shift”:null,     “ floor”:null,     “类型”:typeObj }];

当我有多张卡并且选择了一个班次时,所有班次都会更新为相同的值。enter image description here

我附加了图片,任何人都可以帮忙!!!!!谢谢。

1 个答案:

答案 0 :(得分:0)

我从模板的<div class="cardBodyDiv" ng-repeat="(k, v) in value">行中删除了重复项,将type: typeObj设置为type: {}进行测试,并在控制器的$ onInit方法中创建了这些变量。它对我有用。

控制器

this.shifts = [{shiftid: 'a', shift: 'A'}, {shiftid: 'b', shift: 'B'}, {shiftid: 'c', shift: 'C'}];
this.floors = [{id: 'f1', floor: 'F1'}, {id: 'f2', floor: 'F2'}, {id: 'f3', floor: 'F3'}];
this.requestsObj = [{ shift: null, floor: null, type: {} }, { shift: null, floor: null, type: {} }, { shift: null, floor: null, type: {} }];

模板

<div class="card whiteBckg" ng-repeat="(key, value) in $ctrl.requestsObj"  ng-if="true">
  <div class="cardHeaderDiv">
    <h4>{{key}}
      <span>X</span>
    </h4>
  </div>
  <div class="cardBodyDiv">
    <md-select ng-model="value.shift" placeholder="Select Shift" required md-no-asterisk="false">
      <md-option ng-value="tm.shiftid" ng-repeat="tm in $ctrl.shifts">{{ tm.shift }}</md-option>
    </md-select>

    <md-select ng-model="value.floor" placeholder="Select Floor" required md-no-asterisk="false">
      <md-option ng-value="fl.id" ng-repeat="fl in $ctrl.floors">{{ fl.floor }}</md-option>
    </md-select>

    <div ng-repeat="(a, b) in value.type" class="chip">
      <i class="fa fa-clock-o"></i>{{ getTotal(key, k, a) }} {{a}}
    </div>
  </div>

  <div class="cardFooterDiv">
    <h4>Add more shifts for this day</h4>
  </div>
</div>

屏幕截图

Screen Shot of output