angularJSのng-optionsを使用して2つのドロップダウンを作成しました。ドロップダウンオプションは、2つの異なる配列type_names
とnames
によって設定されます。どちらの配列も要素としてオブジェクトを含んでいます。あなたはそれがtype: others
とだけ表示オプションをよように私は、2番目のドロップダウンでfilter:{type:'others'}
を使用している見ることができるように、以下のHTMLコードの下別のドロップダウンの選択値に基づいてドロップダウンのオプションをフィルタリングして表示します
<div ng-app="myApp" ng-controller="myCtrl">
<select ng-model="selectedTypeName" ng-options="item.id as item.text for item in type_names">
</select>
<select ng-model="selectedName" ng-options="item.id as item.text for item in names|filter:{type:'others'}">
</select>
</div>
<p>This example shows how to fill a dropdown list using the ng-options directive.</p>
はAngularJSスクリプト
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.type_names = [
{id: '0', type: 'me', text: 'Master of Computer Engineering'},
{id: '1', type: 'msc', text: 'Master of Computer Science'},
{id: '2', type: 'others', text: 'Others'}
];
$scope.names = [
{id: '', type: 'choose', text: 'Choose a Program'},
{id: '0', type: 'msc', text: 'Masters - Information Systems Management'},
{id: '1', type: 'msc', text: 'Masters - Software Engineering'},
{id: '2', type: 'msc', text: 'Masters - Computer Security'},
{id: '3', type: 'others', text: 'Bachelors of Computer Science'},
{id: '4', type: 'others', text: 'Exchange Program'},
{id: '5', type: 'others', text: 'Study Abroad'},
{id: '6', type: 'others', text: 'Scientific Summer School'},
{id: '7', type: 'others', text: 'French Summer School'},
{id: '8', type: 'me', text: 'ME - Global IT Management'},
{id: '9', type: 'me', text: 'ME - Software Development and Multimedia'},
{id: '10', type: 'me', text: 'ME - Systems, Networks and Security'}
];
});
です。次に、最初のドロップダウンで選択したオプションに基づいて、タイプ値(me
、others
またはmsc
)を自動的にfilter:{type:'others'}
に入力します。スケーラビリティと堅牢性のために、私はHTML(小枝)コードの中でif/else条件を使いたくありません。
注:私はSymfony2のでAngularJSを使用しようとしています(PHPフレームワーク)
任意のアイデア?
ありがとうございます。完全に動作します:) – utkarsh2k2
2番目の答えは再び本当に役立ちます。 – utkarsh2k2
ところで、AngularJSとSymfonyフォームの使い方は? – utkarsh2k2