4

私が達成しようとしているのは、「親」コンボボックスに依存するアイテムを子コンボボックスに取り込むことです。

問題を明確にするために、このリンクの下にフィドルを作成しました

コンボボックスの「アイテム」は、コンボボックスの「グループ」が変更されるたびに入力する必要があります。

コントローラ:

function Controller( $scope ) {    
    var groups = [ ]; // ommitted for the sake of clarity
    
    $scope.groups = groups;                 // <- linked to cboGroup
    $scope.currentGroup = groups[0];        // <- should be updated from combobox
    $scope.currentItems = $scope.currentGroup.Items;  // <- linked to cboItems
    $scope.currentItem = $scope.currentItems[0];      // <- should be updated from cboItems
}

意見

<select data-ng-model="currentGroup" data-ng-options="group.Name for group in groups"></select>
<select data-ng-model="currentItem" data-ng-options="item.Name for item in currentItems"></select>

これを宣言的に実現することはできません。これは魔法の JavaScript がなくても動作するはずです。

ご支援いただきありがとうございます

4

4 に答える 4

1

これはあなたが求めているものです:

http://jsfiddle.net/TsxTU/1/

これがどのように機能するかは、selectas labelfor itemingroup構文を使用することです。したがって、最初の選択ボックスでは、ユーザーが選択したものは何でも にバインドされたオブジェクトになりますcurrentGroup。同様のことが行われますcurrentItem

その後、必要に応じて式を使用してその更新を通知し、新しいグループの配列の最初の項目が$watch確実に更新されるようにすることができます。currentItemItems

于 2013-08-06T14:32:20.900 に答える