JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 9th, 2012, 03:14 PM
mmmosias mmmosias is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Posts: 18 mmmosias User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 36 m 55 sec
Reputation Power: 0
Splice string into json array.

I have a array that comes from PHP as a JSON array. I'd like to splice new items in the middle of the array. The code I have to do this is this one:

Code:
                                var k = 1;
  				if ( new_event_date > cur_event_date ) {
					var splice_index = k - 1;
					$(this).before(print_nav);
					var current_event_id = $(this).attr('id');
					current_event_id = current_event_id.substr(2);
					alert ('event id '+event_id+' current id '+current_event_id);
					for ( var n=0; n<events_data.event_id.length; n++ ) { 
						if ( current_event_id == events_data.event_id[n]["0"] ) {
							events_data.event_id.splice(splice_index,0,event_id);
							alert('save event id '+event_id+' splice_index '+n+' data event id '+events_data.event_id[n]["0"]);
							events_data.event_title.splice(splice_index,0,event_title);
							alert('save event id '+event_id+' splice_index '+n+' data event title '+events_data.event_title[n]["0"]);
							events_data.selected_source.splice(splice_index,0,selected_source);
							events_data.channel_id.splice(splice_index,0,channel_id);
							events_data.channel_name.splice(splice_index,0,channel_text);
							events_data.event_site.splice(splice_index,0,event_site);
							events_data.event_url.splice(splice_index,0,event_url);
							events_data.start_date.splice(splice_index,0,start_date_string);
							events_data.start_time.splice(splice_index,0,start_time_string);
							events_data.end_date.splice(splice_index,0,end_date_string);
							events_data.end_time.splice(splice_index,0,end_time_string);
							events_data.event_notes.splice(splice_index,0,event_notes);
							break;
						}
					}
					return false;
				}


events.data is a json array of arrays from PHP. The splice method only seems to put the first char of the string within the new item in the array. For example, if for event_id e901, events_data.event_id[splice_index]["0"] only prints "e", similarly for the events_data.event_title. What must I fix in the script to put the entire string?

Reply With Quote
  #2  
Old August 9th, 2012, 04:41 PM
AndrewSW's Avatar
AndrewSW AndrewSW is offline
JavaScript is not spelt java
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2011
Location: Landan, England
Posts: 743 AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 23 h 1 m 13 sec
Reputation Power: 164
A wild stab in the dark suggests

Code:
var tempsp = events_data.event_id[n];
tempsp.splice(splice_index,0,event_id);

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Splice string into json array.

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap