下拉列表在我的更新语法angularjs中传递空值

下拉列表在我的更新语法angularjs中传递空值

本文介绍了下拉列表在我的更新语法angularjs中传递空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个Web应用程序,其中我在 c# angularjs

I am creating a web app in which i am using c# with angularjs

当前,我正在更新记录,其中有一个名为 zone 的下拉列表,看起来像这样

currently i am updating my records in which i have one dropdownlist called zone which looks like this

<select ng-model="uzone" ng-change="locationupd(c)">
  <option ng-repeat="l in gzone" value="{{l.jzone}}">{{l.jzone}}</option>
</select>

但下拉列表中的第一个字段显示为空白,而不是第一个值区域

but the first field in the dropdown is showing blank instead of the first value of zone

有人可以帮我吗?

推荐答案

昨天我在工作中遇到了类似情况。

我的下拉列表必须列出所有国家/地区的名称。

现在,我可以为下拉列表设置默认值。

I dealt with a similar situation yesterday at work.
My drop down list had to list the names of all countries.
I am now able to set a default value for the drop down list.
Please change the code according to your needs.

我要做的是:将CH / Switzerland设置为vm.selectedCountry的默认值。

What I had to do: Set CH/Switzerland as default value for vm.selectedCountry.

代码笔代码(使用选择):

示例:

CodePen code (using select):
Sample:

<select class="selector" ng-model="vm.selectedCountry" ng-options="country.name for country in vm.countries" ng-init="vm.selectedCountry = {'name': 'Switzerland', 'code': 'CH', 'init': true}">

<!--shows only when ng-init is run-->
    <option value="" ng-show="vm.selectedCountry.init">Switzerland</option>

</select>

CodePen代码添加默认值(使用md- select和Angular Material):

样本:

CodePen code (using md-select and Angular Material):
Sample:

<md-select ng-model="vm.selectedCountry" ng-init="vm.selectedCountry = vm.selectedCountry?selectedCountry : 'CH';">

                    <md-option ng-value="'CH'" ng-selected="vm.selectedCountry == 'CH'?true:false">Switzerland</md-option>

                    <md-option ng-repeat="country in vm.countries" ng-value="country.code">
                        {{country.name}}
                    </md-option>
</md-select>

,默认值是从数组中拼接出来的,然后放在md-select中(否则会发生重复)。

In the above one, the default value is spliced from the array and put first in md-select (else, duplication occurs).

这篇关于下拉列表在我的更新语法angularjs中传递空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 03:08