0

Under the following scenario, when a client is selected, I would like to update in the gallery model. 如何使用选定的客户端更新画廊模型?

<form novalidate>
            <div class="control-group">
                <label for="galleryName">Gallery Name:</label>
                <input value="{{gallery.galleryName}}" id="galleryName" type="text" ng-model="gallery.galleryName">
                <p>{{gallery}}</p>
            </div><!-- /control-group -->

            <div class="control-group">
                <label for="clientName">Client Name:</label>
                <select name="client" ng-model="clientList" ng-options="client.id as client.clientName for client in clients" >
                    <option value="">Choose Client</option>
                </select>
                {{clientList}}
            </div>
        </form>

画廊模型示例:

{"id":"57","galleryName":"Sam","clientRef":"205","client":"245","favorited":"1","timestamp":"1374524146"}

我的目标是在更改 clientList 时更改“客户端”。

4

1 回答 1

1

你可以使用$scope.$watch,你可以做这样的事情

$scope.$watch('clientList', function (oldValue, newValue) {
    $scope.gallery.client = newValue; //newValue is the client.id
});

顺便说一句,您应该重命名clientList为其他名称,因为您选择的只是一项

于 2013-08-01T05:09:15.757 回答