1

この例を考えてみましょう。それぞれに固有のクライアントが選択されているギャラリーのリストがあります。特定のギャラリーのクライアントを変更することもできます。これを行うために、選択/オプション リストにクライアント リストを作成しました。

<select ng-model="clientList" ng-options="client.id as client.clientName for client in clients" >
     <option value="">Choose Client</option>
</select>

リストは DB から取り込まれます。通常、アイテムを選択するには client.id を使用します。Angularjs は初めてなので、独自の値を value="" に割り当てているようです。私の例では、ギャラリー テーブルには、client テーブルと client.id に関連する一意の clientID をリストする client 列があります。正しいクライアントを選択するにはどうすればよいですか?

コントローラ

function imageGalleryCtrl ($scope, images, clients, galleries)
{

    $scope.panes = [
        { title:"Home", content:"/beta/application/views/images/uploader/create.html", active: true },
        { title:"Upload", content:"/beta/application/views/images/uploader/upload.html"},
        { title:"Edit", content:"/beta/application/views/images/uploader/edit.html"}
    ];

    //close modal
    $scope.close = function () {
        $scope.imageUploader = false;
    };

    //get gallery info on click from table
    $scope.getGallery = function(id, gallery)
    {
        //set gallery ID to scope
        $scope.galleryID = id;

        //open the modal
        $scope.imageUploader = true;

        //get gallery information
        $scope.galleryCollection = galleries.getGallery(id);

        $scope.galleryCollection.then(function(galleries){
            $scope.gallery = galleries.thisGal;
        });

        //get clients
        $scope.clientCollection = clients.getClients();

        $scope.clientCollection.then(function(clients){
            $scope.clients = clients.clients;
            //Set client
        });

        //get all the images 
        $scope.imgCollection = images.getImages(id);

        $scope.imgCollection.then(function(images){
            $scope.images = images.thisGal_images;
        });
    };
}

サービス

myApp.factory('galleries', function ($http, $q)
{
    return {
        getGallery: function (id)
        {
            var deferred = $q.defer(id);

            $http.post('/beta/images/get/', {id: id}).success(function(data)
            {
                deferred.resolve(data);
            });

            return deferred.promise;
        }
    };
});

クライアント サービスはほとんど同じで、適切な URL を参照するだけです。

助けてくれてありがとう

console.log

4

1 に答える 1