두 가지 선택 요소가 있습니다. 첫 번째는 국가를 선택하는 데 사용됩니다. 두 번째는 상태를 선택하는 데 사용됩니다.
모든 주가 국가에 묶여 있습니다.
상태 :
[{"code":"SC","name":"Santa Catarina","country":{"code":"BRA","name":"Brazil"}}, {"code":"RR","name":"Roraima","country":{"code":"BRA","name":"Brazil"}},{"code":"AL","name":"Alabama","country":{"code":"USA","name":"United States"}},{"code":"FL","name":"Florida","country":{"code":"USA","name":"United States"}}]
국가 :
[{"code":"BRA","name":"Brasil"},{"code":"USA","name":"United States"}]
HTML 내용 :
<select ng-model="userCountry" ng-options="country.name for country in countries track by country.name">
<select ng-model="userState" ng-options="state.name for state in states track by state.name | filter: {state.country.code:userCountry.code}">
따라서 먼저 사용자가 "userCountry"에 연결된 국가를 선택합니다.
$scope.userCountry = new Object();
이제 주 선택 요소는 해당 국가와 관련된 주만 표시해야하지만 현재 모든 주를로드하고 있습니다. 작동하지 않습니다 :(
Im이 올바른 구문을 사용하는지 모르겠습니다. 누구든지 나를 도울 수 있습니까?
이것은 내 필터입니다.
| filter: {state.country.code:userCountry.code}
성공하지 못한 채 다양한 변형을 시도했습니다.
다음은 내 문제가있는 바이올린입니다. http://jsfiddle.net/zrm7y80s/2/
각도 1.2.23을 사용합니다.
감사합니다!!
ng- 옵션을 다음과 같이 변경하십시오.
<select ng-model="userState" ng-options="state.name for state in ( states | filter: {country: { code: userCountry.code }}) track by state.name">
추적을 수행하기 전에 필터를 실행하고, 또한 state.country.code가 객체 키로 유효하지 않기 때문에 하위 객체를 필터링하려고합니다.
업데이트 된 Fiddle : http://jsfiddle.net/dw20jakt/
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다