2016-10-05 7 views
0

新しく追加された項目をhttp.postedにした後に、それをプッシュするための正しい構文を見つけようとしています。

以下の構文ではエラーは表示されませんが、正しく押されません。すべてのアイデアは

$scope.insertAppointmentReminderEntry = function() { 

    $scope.add_reminder_time  = this.add_reminder_time; 
    $scope.add_reminder_timeunit = this.add_reminder_timeunit; 
    $scope.add_delivery_method = this.add_delivery_method; 
    $scope.add_delivery_contact = this.add_delivery_contact; 

    var data = { 
     group_id    : $scope.groupid, 
     appointment_id   : $scope.appointmentid, 
     reminder_time   : $scope.add_reminder_time, 
     reminder_timeunit  : $scope.add_reminder_timeunit, 
     delivery_method  : $scope.add_delivery_method, 
     delivery_contact  : $scope.add_delivery_contact 
    }; 

     $http.post(urlApiAppointmentReminders + $scope.groupid, data).success(function(data, status) { 

      var newItemNo = $scope.appointmentreminders.length+1; 

      $scope.appointmentreminders.push($scope.appointmentreminders[newItemNo].data); 
    }) 

    modalInstance.close(); 
}; 

HTML

<div ng-repeat="x in appointmentreminders" class="row" ng-style="{ 'border-top' : (x.delivery_method != appointmentreminders[$index-1].delivery_method && $index != 0 ? '1pt solid #eee' : '0pt solid #eee')}" style="border-top:1pt solid #eee; padding: 0.25em 0 0.25em 0" > 

    <div class="col-md-offset-1 col-md-4"> 
       @{{x.time}} @{{x.timeunit}}@{{x.time > 1 ? 's' : ''}} prior to appointment 
    </div> 

    <div class="col-md-4"> 
       Reminder: @{{x.delivery_contact}} 
    </div> 

    <div class="col-md-2">     
       <!-- delete this reminder --> 
       <a class="btn btn-xs btn-warning pull-right glyphicon glyphicon-trash" ng-click="ctrl.removeItem($index)"></a>   
    </div> 

    </div> <!-- ng-repeat --> 

HTML(新しいリマインダーを追加するモーダル)

<script type="text/ng-template" id="addScheduleModalContent.html"> 
    <div class="modal-header"> 
     <h3 class="modal-title">Add a new appointment reminder</h3> 
    </div> 
    <div class="modal-body"> 

     <div class="row" style="padding: 0.5em 0 0.5em 0.5em"> 
       <div class="col-sm-4" > 
        {!! Form::text('reminder_time', '30', ['class' => 'form-control', 'placeholder' => '', 'ng-model' => 'add_reminder_time']) !!} 
       </div> 
       <div class="col-sm-8" > 
        {!! Form::select('reminder_timeunit', ['minute' => 'minutes(s)', 'hour' => 'hour(s)', 'day' => 'day(s)', 'week' => 'week(s)', 'month' => 'month(s)'], null, ['class' => 'form-control', 'ng-model' => 'add_reminder_timeunit']) !!} 
       </div> 
     </div> 

     <div class="row" style="padding: 0.5em 0 0.5em 0.5em"> 
       <div class="col-sm-4" > 
        {!! Form::select('delivery_method', ['eml' => 'Email'], null, ['class' => 'form-control', 'ng-model' => 'add_delivery_method']) !!} 
       </div> 
       <div class="col-sm-8" > 
        {!! Form::text('delivery_contact', null, ['class' => 'form-control', 'placeholder' => 'Your email address', 'ng-model' => 'add_delivery_contact']) !!} 
       </div> 
     </div> 

    <div class="modal-footer"> 
     <button class="btn btn-primary" ng-click="insertAppointmentReminderEntry()">Save</button> 
     <button class="btn btn-primary" ng-click="$close()">Close</button> 
    </div> 
    </script>   
+1

でそれらを結合していません。オブジェクトを配列にプッシュしたくないのですか? – charlietfl

+0

私はあなたが正しいと確信しています、私は少しjsで失われる。例えば、$ scope.add_reminder_timeを$ scope.reminder_timeに変更してAPI名に一致させることを意味します。 – user3489502

+0

'ng-model =" reminder.time "' ... 'ng-model =" reminder.contact ".. .. etc ...' $ http.post'に '$ scope.reminder'を送り、プロパティと個々の変数名を手動でコピーするのをスキップします – charlietfl

答えて

0

これは十分な$scope.appointmentreminders.push(data)

またはあなたが入れたい場合でなければなりません役立つだろう配列内の特定の位置に新しいデータがある場合は、これを実行します $scope.appointmentreminders[newItemNo] = data

しかし、自分で `NG-model`で単一のオブジェクトを使用し、` $ http.post`に直接そのオブジェクトを渡すことで、プロパティ名の重複がたくさん保存一行:)

+0

は、応答の' data'が完全なオブジェクトであることを確認する必要がありますしかし、2つの変数 'data'があるので – charlietfl

+0

ありがとう!プッシュは機能しますが、新しい項目が表示されますが、(私がリフレッシュしない限り)データは表示されません。 @charlietflのように、私は自分の不動産名を混乱させるかもしれない。上に追加されたコード – user3489502

+0

ちょうど 'data'に' data:{"success":true} 'が含まれていることに気付きました。名前を変更しますか?私はそれを試してみます – user3489502

関連する問題