0

次のようなバッキング JSON を含むドロップダウンがあります。

$scope.tradestyles = [
    {"id":"1","source":"Source One","name":"Name One"},
    {"id":"2","source":"Source Two","name":"Name Two"}
]

これは を使用したドロップダウンですselect2。モデルは選択したトレードス​​タイルの ID です。

<select id="tradestyle" ui-select2 ng-model="currentTradestyle" >
    <option ng-repeat="tradestyle in tradestyles" value="{{tradestyle.id}}">
        {{tradestyle.name}}
    </option>
</select>

その横に、選択したトレードス​​タイルの名前が表示され、編集できるテキスト フィールドを配置したいと考えています。

<input type="text" ng-model="currentTradestyle" />

後者のモデルを変更して、ID ではなく選択したトレードス​​タイルの名前を指すようにするにはどうすればよいですか? つまり、スコープ オブジェクトをトラバースして、選択した ID 値の兄弟名の値を指すにはどうすればよいでしょうか。

4

3 に答える 3

2

あなたの質問を正しく理解していればng-options、フィールドではなくオブジェクトへのバインドに使用する必要があります。だからそれはなる

 <select id="tradestyle" ui-select2 ng-model="currentTradestyle" ng-options="style.name for style in tradestyles">

        </select>
 <input type="text" ng-model="currentTradestyle.id" />
 <input type="text" ng-model="currentTradestyle.name" />

ここで私のフィドルを参照してください http://jsfiddle.net/cmyworld/UsfF6/

于 2014-02-28T13:55:23.867 に答える