利用可能なプロパティのリストに基づいて任意の数のソートプロパティを定義できるようにすることで、名前。コード:ng-repeatを使用してng-repeat内のAngularJS動的選択 - 既定の選択されたオプションを設定
はJavaScript(コントローラ)
$scope.data.sortInfo = {};
$scope.data.sortInfo.availableProperties = [
{ PropertyName: "ProjectName", PropertyDisplayName: "Name" },
{ PropertyName: "LastUpdateOnAnsiStr", PropertyDisplayName: "Updated" },
{ PropertyName: "LocationsStr", PropertyDisplayName: "Locations" }
];
// array of selected properties to sort by {Name: {property name}, Direction: {0 = ASC/1 = DESC}, Priority: {index of sort field (auto filled)} }
$scope.data.sortInfo.selectedProperties = [
{ Name: "ProjectName", Direction: 0, Priority: 0 }
];
HTMLこれを行う
<td ng-repeat="currentSelectedProperty in data.sortInfo.selectedProperties track by $index">
<!-- debug info -->
{{currentSelectedProperty.Name}} - {{currentSelectedProperty.Direction}} - {{currentSelectedProperty.Priority}}
<select ng-model="currentSelectedProperty.Name"
ng-options="item as item.PropertyDisplayName for item in data.sortInfo.availableProperties track by item.PropertyName">
</td>
、select
が正しく表示され、人口が、私は選択されていないオプションが用意されていません。ドロップダウンにProjectName
が表示されると思います。
また、selectの値を変更すると、デバッグフィールド(名前、方向、優先度)に表示される情報が正しく変更されるため、ng-model
が正常に動作しているようです。
私はng-options
と明示的ng-repeat
オプションを使用しないことで回避策を見つけるために管理している:
<option ng-selected="{{item.PropertyName == currentSelectedProperty.Name}}"
ng-repeat="item in data.sortInfo.availableProperties"
value="{{item.PropertyName}}">
{{item.PropertyDisplayName}}
</option>
質問:私のNG・オプション・アプローチと間違って何ですか?
角度バージョンは1.4.3です。
ありがとうございます!
currentSelectedProperty.Nameの値は何ですか? –
'currentSelectedProperty.Name'はどちらの場合でも' 'ProjectName''です。 – Alexei