2017-05-07 5 views
0

Ich verwende Angular JS mit Syncfusion und Zeitplan Komponente. Ich habe eine Pause im asp.net Kern gemacht und ich habe einen Client dafür in angularjs gemacht. Ich versuche, alle Termine für die Zeitplankomponente zu erhalten, wenn sie jedoch der Bereichsvariable zugewiesen werden, die für die Zeitplanung gebunden wird, kommt es zu einem Fehler. Ich habe versucht, diesen Fehler zu googeln, aber ich habe nichts Nützliches gefunden und ich bin noch nicht sehr gut in eckigen oder Javascript.n.sort ist kein Funktionsfehler

Wenn ich ein Array mit Terminobjekten manuell erstellen, funktioniert es, aber wenn ich es von meinem Terminservice übergeben habe, tut es nicht.

Dies ist der Fehler:

angular.js:14525 TypeError: n.sort is not a function 
at Object._sortAppById (http://cdn.syncfusion.com/15.1.0.41/js/web/ej.web.all.min.js:10:3533264) 
at Object._dataProcessing (http://cdn.syncfusion.com/15.1.0.41/js/web/ej.web.all.min.js:10:3536745) 
at Object._bindAppointmentsData (http://cdn.syncfusion.com/15.1.0.41/js/web/ej.web.all.min.js:10:3529006) 
at Object._init (http://cdn.syncfusion.com/15.1.0.41/js/web/ej.web.all.min.js:10:3298250) 
at Object.<anonymous> (http://cdn.syncfusion.com/15.1.0.41/js/web/ej.web.all.min.js:10:21539) 
at r.fn.init.n.fn.(anonymous function) [as ejSchedule] (http://cdn.syncfusion.com/15.1.0.41/js/web/ej.web.all.min.js:10:22796) 
at Object.post (http://cdn.syncfusion.com/15.1.0.41/js/common/ej.widget.angular.min.js:10:9542) 
at https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js:17:3 
at ra (https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js:85:35) 
at n (https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js:70:226) "<ej-schedule id="Schedule1" e-width="100%" e-height="525px" e-currentview="currentView" e-currentdate="Date" e-appointmentsettings-datasource="appointments" e-appointmentsettings-id="id" e-appointmentsettings-subject="name" e-appointmentsettings-starttime="startTime" e-appointmentsettings-endtime="endTime" e-appointmentsettings-description="comments" e-appointmentsettings-allday="isAllDay" e-appointmentsettings-recurrence="isRecurrence" e-appointmentsettings-recurrencerule="recurrenceRule" e-directive-name="ejSchedule" class="e-schedule e-js e-scheduleouter e-tooltip" tabindex="1" style="width: 100%; height: 525px;" role="presentation">" 

Diese meine Funktion ist sie in der Steuerung von Service zu erhalten: `

appointmentsService.getAppointments().then(function (results) { 
     $scope.appointments = results.data; 
     console.log($scope.appointments); 
    }); 

und dann ist mein Service:

(function() { 

    'use strict'; 

    var app = angular.module("myApp"); 

    app.factory('appointmentsService', ['$http', function($http) { 

     var serviceBase = 'http://localhost:63185/'; 
     var appointmentsServiceFactory = {}; 

     var _getAppointments = function() { 
      return $http.get(serviceBase + 'api/appointments').then(function (results) { 
       return results; 
      }); 
     }; 

     appointmentsServiceFactory.getAppointments = _getAppointments; 

     return appointmentsServiceFactory; 

    }]); 

}()); 

Antwort

0

Fügen Sie bitte das folgende Codebeispiel in Ihre Web-API-Dienst-Projektsteuerungsdatei ein.

public List<DefaultSchedule> GetData() 
    { 

     List<DefaultSchedule> datas = _context.DefaultSchedule.Take(500).ToList(); 
     return datas; 
    } 
    [HttpPost] 
    public List<DefaultSchedule> Batch([FromBody] EditParams param) 
    { 
     if (param.action == "insert" || (param.action == "batch" && (param.added.Count > 0))) // this block of code will execute while inserting the appointments 
     { 
      DefaultSchedule appoint = new DefaultSchedule(); 
      object result; 
      if (param.action == "insert") 
      { 
       var value = param.value; 
       foreach (var fieldName in value.GetType().GetProperties()) 
       { 
        var newName = fieldName.ToString().Split(null); 
        if (newName[1] == "Id") result = (_context.DefaultSchedule.ToList().Count > 0 ? _context.DefaultSchedule.ToList().Max(p => p.Id) : 1) + 1; 
        else if (newName[1] == "StartTime" || newName[1] == "EndTime") result = Convert.ToDateTime(fieldName.GetValue(value)); 
        else result = fieldName.GetValue(value); 
        fieldName.SetValue(appoint, result); 
       } 
       _context.DefaultSchedule.Add(appoint); 
      } 
      else 
      { 
       foreach (var item in param.added.Select((x, i) => new { Value = x, Index = i })) 
       { 
        var value = item.Value; 
        foreach (var fieldName in value.GetType().GetProperties()) 
        { 
         var newName = fieldName.ToString().Split(null); 
         if (newName[1] == "Id") result = (_context.DefaultSchedule.ToList().Count > 0 ? _context.DefaultSchedule.ToList().Max(p => p.Id) : 1) + 1 + item.Index; 
         else if (newName[1] == "StartTime" || newName[1] == "EndTime") result = Convert.ToDateTime(fieldName.GetValue(value)); 
         else result = fieldName.GetValue(value); 
         fieldName.SetValue(appoint, result); 
        } 
        _context.DefaultSchedule.Add(appoint); 
       } 
      } 
      _context.SaveChanges(); 
     } 
     if ((param.action == "remove") || (param.action == "batch" && (param.deleted.Count > 0))) // this block of code will execute while removing the appointment 
     { 
      if (param.action == "remove") 
      { 
       DefaultSchedule app = _context.DefaultSchedule.Where(c => c.Id == Convert.ToInt32(param.key)).FirstOrDefault(); 
       if (app != null) _context.DefaultSchedule.Remove(app); 
      } 
      else 
      { 
       foreach (var a in param.deleted) 
       { 
        var app = _context.DefaultSchedule.ToList().Where(c => c.Id == Convert.ToInt32(a.Id)).FirstOrDefault(); 
        if (app != null) _context.DefaultSchedule.Remove(app); 
       } 
      } 
      _context.SaveChanges(); 
     } 
     if (param.action == "update" || (param.action == "batch" && (param.changed.Count > 0))) // this block of code will execute while updating the appointment 
     { 
      var value = param.action == "update" ? param.value : param.changed[0]; 
      var filterData = _context.DefaultSchedule.Where(c => c.Id == Convert.ToInt32(value.Id)); 
      if (filterData.Count() > 0) 
      { 
       DefaultSchedule appoint = _context.DefaultSchedule.Single(A => A.Id == Convert.ToInt32(value.Id)); 
       appoint.StartTime = Convert.ToDateTime(value.StartTime); 
       appoint.EndTime = Convert.ToDateTime(value.EndTime); 
       appoint.Subject = value.Subject; 
       appoint.Recurrence = value.Recurrence; 
       appoint.AllDay = value.AllDay; 
       appoint.RecurrenceRule = value.RecurrenceRule; 
      } 
      _context.SaveChanges(); 
     } 
     List<DefaultSchedule> datas = _context.DefaultSchedule.Take(500).ToList(); 
     return datas; 
    } 

Bitte umfassen das folgende Codebeispiel in Ihrem AngularJS Frontend Seite probieren.

<body> 
<div class="content-container-fluid"> 
    <div class="row"> 
     <div class="cols-sample-area"> 
      <div ng-controller="ScheduleCtrl"> 
       <ej-schedule id="Schedule1" e-width="100%" e-height="525px" e-currentview="currentview" e-currentdate="setDate" 
        e-appointmentsettings-datasource="appointments" 
        e-appointmentsettings-id="Id" 
        e-appointmentsettings-subject="Subject" 
        e-appointmentsettings-starttime="StartTime" 
        e-appointmentsettings-endtime="EndTime" 
        e-appointmentsettings-description="Description" 
        e-appointmentsettings-allday="AllDay" 
        e-appointmentsettings-recurrence="Recurrence" 
        e-appointmentsettings-recurrencerule="RecurrenceRule" 
        e-appointmentsettings-applyTimeOffset="false"> 
       </ej-schedule> 
      </div> 
     </div> 
    </div> 
</div> 

<script> 
    angular.module('ScheduleApp', ['ejangular']).controller('ScheduleCtrl', function ($scope) { 
     $scope.appointments = ej.DataManager({ 
      // get the required appointments from Web API service 
      url: "http://localhost:15154/api/Schedule/GetData", 
      crudUrl: "http://localhost:15154/api/Schedule/Batch", 
      adaptor: new ej.UrlAdaptor() 
     }); 
     $scope.setDate = new Date(2014, 11, 5); 
     $scope.currentview = "week"; 
    }); 
</script> 

das Service-Projekt zum ersten Mal ausgeführt und auf dem Laufzustand halten. Ändern Sie dann die obige Codebeispiel-Service-URL in der Frontend-HTML-Seite.

Verwandte Themen