0

当我单击编辑项目按钮时,模态隐藏淡入淡出将显示项目详细信息。我想将更改后的日期值恢复到我的 item.date.sDate 中,但它不起作用。

 <div class="modal hide fade" id="editdetails">
  <div class="modal-header"><h3>Update Project Information</h3></div>
  <div class="modal-body">
  <label>Project: </label>
    <input type="text" value= {{item.data.project}} class="span3" id="appendedDropdownButton" ng-model="item.data.project"><br>
  <label>Start Date: </label>
    <input type="text" value= {{item.data.sDate}} class="span3" id="datepicker1" ng-model="item.data.sDate"><br>
  <label>End Date: </label>
    <input type="text" value= {{item.data.eDate}} class="span3" id="datepicker2" ng-model="item.data.eDate"><br>
   </div>
    <br>
    <div class="modal-footer">
        <a href="#" class="btn close_btn" data-dismiss="modal">Close</a>
        <a href="#" class="btn btn-primary save_btn" ng-click="update(item.id)">Save Changes</a>
    </div>
  </div>

关于日期选择器的 Javascript,它们将日期更改为文本。

  $( "#datepicker1" ).datepicker({
               inline: true,
               dateFormat: 'dd/mm/yy',
               onSelect: function(dateText) {
                   $("#datepicker2").datepicker("option","minDate", dateText)
                   var modelPath = $(this).attr('ng-model');
                   putObject(modelPath, $scope, dateText);
                   $scope.$apply();
                }
});

$( "#datepicker2" ).datepicker({
               inline: true,
               dateFormat: 'dd/mm/yy',

               onSelect: function(dateText) {
                   $("#datepicker1").datepicker("option","maxDate", dateText)
                   var modelPath = $(this).attr('ng-model');
                   putObject(modelPath, $scope, dateText);
                   $scope.$apply();
               }
});
4

1 回答 1

0

您应该使用指令来设置您的日期选择器。幸运的是,Angular-UI 已经为你做到了。

<div ng-controller="MyCtrl">
    <input ng-model="date" ui-date ng-change="dateChanged()"/><br/>
     Selected Date: {{date | date: 'MMM d yyyy'}}
</div>

然后在你的控制器中:

app.controller('MyCtrl', function($scope){ 
    $scope.dateChanged = function (){
        console.log('Date is: ' + $scope.date);
    };
});
于 2013-02-12T19:11:05.553 回答