Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Pobieranie danych z bazy danych, Pobieranie danych z bazy danych
K3n0
post
Post #1





Grupa: Zarejestrowani
Postów: 46
Pomógł: 0
Dołączył: 3.05.2016

Ostrzeżenie: (0%)
-----


Witam, Tak jak w tytule mam problem z pobieraniem danych z tablicy. Musze pobrać wszystkie elementy z tablicy save_events. W controllerze zrobilem zapytanie wyglada mniej wiecej w ten sposob:
  1. $eventColored = DB::table('save_events')->get(['users_id','events_id']);
  2. return response()->json(['eventColored'=>$eventColored])->$eventColored = array('eventColored' => $eventColored );


I jak czytałem za pomoca ajaxa moge pobrac dane i przypisać je do zmiennej, dzieki ktorej bede mogl dopasowac kolor eventu. I tutaj jest pytanie jak przypisać dane do zmiennej, wydaje sie błache ale szczerze nie mam pojecia.

Kod
$.ajax({    
type: "GET",
url: "{!!route('color')!!}",            
dataType: "json",
data:{},                
success: function(data)
     {
        var JSONString=data;
        var JSONObject = JSON.parse(JSON.stringify(data));
            console.log(JSONObject);      
         alert(JSONObject);
       },                                               
});

Ogolnie pobiera mi dane i jak chce sobie sprawdzic allertem wyswietla prawidlowa ilosc tzn jak mam 2 elementy w tablicy to wyswietla mi 2 elementy w allercie ale niestety pokazuje "Object object". Kombinuje na różne sposoby lecz nic nie wychodzi.

Wynik w konsoli:
Object { eventColored: Array[1] }

Ten post edytował K3n0 12.04.2017, 10:34:05
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
K3n0
post
Post #2





Grupa: Zarejestrowani
Postów: 46
Pomógł: 0
Dołączył: 3.05.2016

Ostrzeżenie: (0%)
-----


Kod
console.log(JSONObject.eventColored);

Wynik:
Array [ Object ]

I pytanie jak moge przypisac to do zmienej zeby pozniej moc wykonac funkcje:
Kod
eventAfterRender: function (event, element, view) {
        if(event.id){
            element.css('background-color', '#cccccc');                                            
        }
                else
                 {
                    if (event.title == "Wydzial 1")
                    {
                    element.css('background-color', '#378006');
                    }
                    else if(event.title == "Wydzial 2")
                    {
                    element.css('background-color', '#ff0000');    
                    }
                    else if(event.title == "Wydzial 3")
                    {
                    element.css('background-color', '#73e600');    
                    }
                    else{
                    element.css('background-color', '#0066ff');
                    }
                }
            }

jak robie event.id == JSONObject.eventColored wtedy wywala blad:

jQuery.Deferred exception: JSONObject is not defined .eventAfterRender@http://localhost:8000/home:206:1
publiclyTrigger@http://localhost:8000/js/fullcalendar.js:11387:11
FC.View<.publiclyTrigger@http://localhost:8000/js/fullcalendar.js:8480:10
FC.View<.onEventsRender/<@http://localhost:8000/js/fullcalendar.js:9381:4
FC.View<.renderedEventSegEach@http://localhost:8000/js/fullcalendar.js:9471:6
FC.View<.onEventsRender@http://localhost:8000/js/fullcalendar.js:9380:3
FC.View<.executeEventsRender/<@http://localhost:8000/js/fullcalendar.js:9344:4
Promise.resolve/promise.then@http://localhost:8000/js/fullcalendar.js:1887:29
FC.View<.executeEventsRender@http://localhost:8000/js/fullcalendar.js:9337:10
FC.View<.requestEventsRender/<@http://localhost:8000/js/fullcalendar.js:9298:11
addTask/</runFunc@http://localhost:8000/js/fullcalendar.js:1951:21
addTask/<@http://localhost:8000/js/fullcalendar.js:1968:5
Promise@http://localhost:8000/js/fullcalendar.js:1826:3
addTask@http://localhost:8000/js/fullcalendar.js:1946:10
FC.View<.requestEventsRender@http://localhost:8000/js/fullcalendar.js:9297:10
FC.View<.handleEvents@http://localhost:8000/js/fullcalendar.js:9280:3
FC.View<.setEvents@http://localhost:8000/js/fullcalendar.js:9247:3
FC.View<.bindEvents/<@http://localhost:8000/js/fullcalendar.js:9223:5
resolve/</mightThrow@http://localhost:8000/js/jquery.js:3570:21
resolve/</process<@http://localhost:8000/js/jquery.js:3638:12
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 11.10.2025 - 00:57