Javascript 为什么要改变给予;“未定义”;在angularjs?

Javascript 为什么要改变给予;“未定义”;在angularjs?,javascript,angularjs,Javascript,Angularjs,你能告诉我为什么用angularjs表示“未定义”吗 $scope.onChangedCityDropDown= function(i){ console.log(i) } <select class="form-control" ng-model="a" ng-options="item.city as item.city for item in vals" ng-change="onChangedCityDropDown(item)">

你能告诉我为什么用angularjs表示“未定义”吗

$scope.onChangedCityDropDown= function(i){
    console.log(i)
}
<select class="form-control" ng-model="a"
        ng-options="item.city as item.city for item in vals" 
        ng-change="onChangedCityDropDown(item)">
    <option value="" disabled>choose an option</option>
</select>
$scope.onChangedCityDropDown=函数(i){
控制台日志(i)
}
选择一个选项
这是我的密码

您可以直接将ng模型值传递给函数

 <select class="form-control" ng-model="a" ng-options="item.city as item.city for item in vals" ng-change="onChangedCityDropDown(a)">
    <option value="" disabled>choose an option</option>
 </select>

选择一个选项

您可以直接将ng模型值传递给函数

 <select class="form-control" ng-model="a" ng-options="item.city as item.city for item in vals" ng-change="onChangedCityDropDown(a)">
    <option value="" disabled>choose an option</option>
 </select>

选择一个选项

ng选项
的工作方式与
ng repeat
的工作方式不同。除了
ng选项
属性值之外,您不会获得
值。要使其工作,您应该在
ng change
回调函数中使用
ng model
(a)值

ng-change="onChangedCityDropDown(a)"
您还需要根据城市选择设置
状态
,然后将ng选项更改为以下

ng-options="item.state as item.city for item in vals"

ng选项的工作方式与
ng repeat
的工作方式不同。除了
ng选项
属性值之外,您不会获得
值。要使其工作,您应该在
ng change
回调函数中使用
ng model
(a)值

ng-change="onChangedCityDropDown(a)"
您还需要根据城市选择设置
状态
,然后将ng选项更改为以下

ng-options="item.state as item.city for item in vals"

只需将
onChangedCityDropDown(项目)
更改为
onChangedCityDropDown(a)


只需将
onChangedCityDropDown(项目)
更改为
onChangedCityDropDown(a)


只需更改ng选项,如下所示,这将为您提供所需的对象

ng-options="item as item.city for item in vals"
ng-change="onChangedCityDropDown(a)"
ng change
中,您必须通过
ng型号


这是工作

只需按以下方式更改ng选项,这将为您提供所需的对象

ng-options="item as item.city for item in vals"
ng-change="onChangedCityDropDown(a)"
ng change
中,您必须通过
ng型号


以下是工作示例

您可以尝试以下城市和州参考选择代码,也请检查您给定的工作示例

控制器:

$scope.vals = [{
    "city":"gurgaon",
    "state":"Haryana"
  }, {
    "city":"Manesar",
    "state":"Haryana"
  }, {
    "city":"Bangalore",
    "state":"Karnataka"
  }]; 

  $scope.onChangedCityDropDown= function(i){
    console.log(i)
  }

  $scope.onChangedStateDropDown= function(i){
    console.log(i)
  }
City
<select  class="form-control" ng-model="city" ng-options="item.city as item.city for item in vals" ng-change="onChangedCityDropDown(city)">
    <option value="" disabled>Select City</option>
</select>
State
<select  class="form-control" ng-model="state" ng-options="item.state as item.state for item in vals | filter:{city:city}" ng-change="onChangedStateDropDown(state)">
    <option value="" disabled>Select State</option>
</select>
模板:

$scope.vals = [{
    "city":"gurgaon",
    "state":"Haryana"
  }, {
    "city":"Manesar",
    "state":"Haryana"
  }, {
    "city":"Bangalore",
    "state":"Karnataka"
  }]; 

  $scope.onChangedCityDropDown= function(i){
    console.log(i)
  }

  $scope.onChangedStateDropDown= function(i){
    console.log(i)
  }
City
<select  class="form-control" ng-model="city" ng-options="item.city as item.city for item in vals" ng-change="onChangedCityDropDown(city)">
    <option value="" disabled>Select City</option>
</select>
State
<select  class="form-control" ng-model="state" ng-options="item.state as item.state for item in vals | filter:{city:city}" ng-change="onChangedStateDropDown(state)">
    <option value="" disabled>Select State</option>
</select>
城市
选择城市
陈述
选择状态

您可以尝试以下城市和州参考选择代码,也请检查您给定的工作示例

控制器:

$scope.vals = [{
    "city":"gurgaon",
    "state":"Haryana"
  }, {
    "city":"Manesar",
    "state":"Haryana"
  }, {
    "city":"Bangalore",
    "state":"Karnataka"
  }]; 

  $scope.onChangedCityDropDown= function(i){
    console.log(i)
  }

  $scope.onChangedStateDropDown= function(i){
    console.log(i)
  }
City
<select  class="form-control" ng-model="city" ng-options="item.city as item.city for item in vals" ng-change="onChangedCityDropDown(city)">
    <option value="" disabled>Select City</option>
</select>
State
<select  class="form-control" ng-model="state" ng-options="item.state as item.state for item in vals | filter:{city:city}" ng-change="onChangedStateDropDown(state)">
    <option value="" disabled>Select State</option>
</select>
模板:

$scope.vals = [{
    "city":"gurgaon",
    "state":"Haryana"
  }, {
    "city":"Manesar",
    "state":"Haryana"
  }, {
    "city":"Bangalore",
    "state":"Karnataka"
  }]; 

  $scope.onChangedCityDropDown= function(i){
    console.log(i)
  }

  $scope.onChangedStateDropDown= function(i){
    console.log(i)
  }
City
<select  class="form-control" ng-model="city" ng-options="item.city as item.city for item in vals" ng-change="onChangedCityDropDown(city)">
    <option value="" disabled>Select City</option>
</select>
State
<select  class="form-control" ng-model="state" ng-options="item.state as item.state for item in vals | filter:{city:city}" ng-change="onChangedStateDropDown(state)">
    <option value="" disabled>Select State</option>
</select>
城市
选择城市
陈述
选择状态

您需要通过
a
一次更改的ITHydropdown(a)
我认为您需要
ng options=“item.city as item for item in vals”
使用a代替您需要通过
a的item,即
一次更改的ITHydropdown(a)
我认为您需要
ng options=“item.city as item for item in vals”
使用替代项I想要选定的对象I想要相应的状态值I想要选定选项或对象的“状态”值I想要相应的状态值如果选择“gurgaon”状态应该是“haryana”如果选择“gurgaon”状态应该是“haryana”我想要选定的对象I想要相应的状态值I想要“状态”所选选项或对象的值我想要对应的状态值如果我选择“gurgaon”状态应该是“haryana”如果我选择“gurgaon”状态应该是“haryana”我想要所选选项或对象的“状态”值我想要对应的状态值如果我选择“gurgaon”状态应该是“haryana”,如果用户选择,这不是我需要的正确答案“gurgoan”或其他选项。我需要它对应的状态值我想要所选选项或对象的“状态”值我想要对应的状态值如果我选择“gurgaon”状态应该是“haryana”如果用户选择“gurgoan”,这不是我需要的正确答案“或其他选项。我需要它对应的状态值让$scope.state=”。但当我更改为“gurgoan”时,它的城市值是“gurgoan”,状态是“haryana”,我将解释我正在尝试做什么。我有一个下拉列表,其中显示城市。关于城市的变化,我想向州政府表示抱歉,我不明白你的意思。在你的例子中,两个城市都在一个城市之下state@Joy您可以从我共享的代码中获得相应的状态值。按i.state获取状态,然后更新或显示您想要的任何位置。让$scope.state=''作为初始值。但当我更改为“gurgoan”时,它的城市值为“gurgoan”,状态为“haryana”,我将解释我正在尝试执行的操作。我有一个下拉列表,其中显示了城市。关于城市的变化,我想向州政府表示抱歉,我不明白你的意思。在你的例子中,两个城市都在一个城市之下state@Joy您可以从我共享的代码中获得相应的状态值。按i.state获取状态,然后根据需要更新或显示。