当我在 select 中选择一个值时标记一个复选框

mark a checkbox when i choose a value in a select

我正在使用一个 JSON 文件,我将这些值放入 select 倍数中,当我 select 一个值在 select 中时,我试图标记一个复选框但我不知道我该怎么做

这是我的 JSON 文件

 "tipocasa": [
        {"tipo":"Propia" , "tipo_casa":1},
        {"tipo":"Rentada" , "tipo_casa":2},
        {"tipo":"Otro" , "tipo_casa":3}
    ]

这是我正在使用的 select 代码 ui-select

          <ui-select multiple ng-model="entrevistainicialModel.idcomportamiento"
                           ng-disabled="false"
                           search-enabled="true"
                           append-to-body="true"
                           class="form-control ">
                    <ui-select-match placeholder="Comportamientos">
                        {{$item.comportamiento}}
                    </ui-select-match>
                    <ui-select-choices repeat="multipleItem.idcomportamiento as multipleItem in datosJson[0].comportamientos | filter: $select.search">
                        {{multipleItem.comportamiento}}
                    </ui-select-choices>
                </ui-select>

这是复选框代码

         <label class="checkbox-inline custom-checkbox nowrap">
            <input align="center" type="checkbox" ng-model="entrevistainicialModel.idcomportamiento" value="1">
                            <span align="center">Propia</span>
                        </label>

             <label class="checkbox-inline custom-checkbox nowrap">
            <input align="center" type="checkbox" ng-model="entrevistainicialModel.idcomportamiento" value="1">
                            <span align="center">rentada</span>
                        </label>

         <label class="checkbox-inline custom-checkbox nowrap">
            <input align="center" type="checkbox" ng-model="entrevistainicialModel.idcomportamiento" value="1">
                            <span align="center">Otro</span>
                        </label>

有什么想法或建议吗?

首先需要添加on-removeon-select来改变模型。 并分配。根据您的需要添加到每个复选框。

我根据你的数据做了一个例子

HTML

    <ui-select multiple ng-model="data.selected" on-remove="$item.selected=false" on-select="$item.selected = true" theme="bootstrap" sortable="true" close-on-select="false" style="width: 800px;">
    <ui-select-match placeholder="Comportamientos...">{{$item.name}}</ui-select-match>
    <ui-select-choices repeat="comportamiento in datosJson.comportamientos">
  {{comportamiento.name}}
    </ui-select-choices>
  </ui-select>              
  <p>Selected: {{data.selected}}</p>

  <div ng-repeat="item in datosJson.comportamientos">
    <input type="checkbox" ng-model="item.selected">{{item.name}}
    <br>
  </div>

控制器

$scope.datosJson = {
comportamientos:
  [
    {id:1, name:'comportamiento1'},
    {id:2, name:'comportamiento2'},
    {id:3, name:'comportamiento3'}
  ]
  };

这是带有 DEMO 的 plnkr 只需更改您的数据。