簡體   English   中英

無法使用angular.js和php在下拉菜單中設置值

[英]Can not set the value in drop down using angular.js and php

從數據庫中獲取數據后,將數據設置為下拉選擇值時遇到一點問題。我在下面解釋我的代碼。

plan.html:

<div class="input-group bmargindiv1 col-md-12">
 <span class="input-group-addon ndrftextwidth text-right" style="width:180px">Date :</span>
<datepicker date-format="MMMM d, y" date-min-limit="2010/01/01" date-max-limit="2020/01/01"button-prev='<i class="fa fa-arrow-circle-left"></i>' button-next='<i class="fa fa-arrow-circle-right"></i>'> 
<input type="text" name="birthdate" class="form-control" ng-model="date" placeholder="Add date" />
 </datepicker>
</div> 
<div class="input-group bmargindiv1 col-md-12">
<span class="input-group-addon ndrftextwidth text-right" style="width:180px">Topic :</span>
<input type="text" name="topic" class="form-control" ng-model="topic" placeholder="Add Topic" />
</div> 
<div class="input-group bmargindiv1 col-md-12">
<span class="input-group-addon ndrftextwidth text-right" style="width:180px">Section:</span>
<select id="coy" name="coy" class="form-control" ng-model="section" ng-options="sec.name for sec in listOfSection track by sec.value " >
<option value="">Select section</option>
</select>
</div>

相關的控制器文件代碼如下。

$scope.listOfSection=[];
    $http({
        method:'GET',
        url:"php/userplan/getSectionData.php",
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
    }).then(function successCallback(response){
        angular.forEach(response.data,function(obj2){
            var data={'name':obj2.section_name,'value':obj2.section_id};
            $scope.listOfSection.push(data);
        });
    },function errorCallback(response) {
    });
$http({
            method:'POST',
            url:"php/userplan/editPlanData.php",
            data:planid,
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
        }).then(function successCallback(response){
            $scope.date=response.data[0].date;
            $scope.topic=response.data[0].topic;
            $scope.section=response.data[0].section_id;
            $scope.buttonName="Update";
            $scope.showCancel =  true;
        },function errorCallback(response) {
        });

在這里, response.data[0].section_id應該在下拉列表中設置為值,並且應該顯示相應的名稱。在這里,我嘗試通過添加$scope.section.value=response.data[0].section_id嘗試,但是它給了我錯誤。在這里,我的要求是將section_id設置為下拉菜單的值,並顯示相應的名稱。請幫助我解決此問題。

you can use like this



<select ng-model="ContentAdditionalInfoModel.AdditionalInfoId"  class="form-control" ng-required="true"
                                                ng-options="item.AdditionalInfoId as item.AdditionalInfoName for item in  AdditionalInfoList">
                                            <option value="" selected="selected">Select</option>
                                        </select>

here AdditionalInfoList come from your database

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM