Javascript.RU

Создать новую тему Ответ
 
Опции темы Искать в теме
  #1 (permalink)  
Старый 02.05.2011, 19:20
Кандидат Javascript-наук
Отправить личное сообщение для TicTac Посмотреть профиль Найти все сообщения от TicTac
 
Регистрация: 07.09.2010
Сообщений: 133

Как смотреть данные добавлены к объекты через data()?
Как можно смотреть данные добавлены к объекты через data(), вот таким вот образом?

var adiv = $("div").get(0);
    jQuery.data(adiv, "test", { first: 16, last: "pizza!" });


Я имею ввиду в firebug, developer tool и тд.

Заранее спасибо!
Ответить с цитированием
  #2 (permalink)  
Старый 02.05.2011, 19:49
Аватар для Amphiluke
   ☽
Отправить личное сообщение для Amphiluke Посмотреть профиль Найти все сообщения от Amphiluke
 
Регистрация: 07.01.2011
Сообщений: 254

Набираете в консоли
console.log(jQuery.data(jQuery("div").get(0)));

и смотрите вывод.

Последний раз редактировалось Amphiluke, 02.05.2011 в 19:53. Причина: Ошибка
Ответить с цитированием
  #3 (permalink)  
Старый 02.05.2011, 19:49
sinistral
Посмотреть профиль Найти все сообщения от melky
 
Регистрация: 28.03.2011
Сообщений: 5,418

Сообщение от TicTac Посмотреть сообщение
Как можно смотреть данные добавлены к объекты через data(), вот таким вот образом?

var adiv = $("div").get(0);
    jQuery.data(adiv, "test", { first: 16, last: "pizza!" });


Я имею ввиду в firebug, developer tool и тд.

Заранее спасибо!
console.log (     jQuery.data( adiv )    )


а если без data(), то хз, потому что я не знаю, как это там реализовывается
Ответить с цитированием
  #4 (permalink)  
Старый 02.05.2011, 20:10
Аватар для Amphiluke
   ☽
Отправить личное сообщение для Amphiluke Посмотреть профиль Найти все сообщения от Amphiluke
 
Регистрация: 07.01.2011
Сообщений: 254

Кстати, если без console.log, то получить доступ к данным, добавленным через .data(), можно через свойства объекта window, на который в глобальной области видимости ссылается ключевое слово this. В Firebug свойства window можно развернуть на вкладке «Наблюдение» при открытом окне «Сценарий».
Данные, добавленные в data, находятся здесь:
Код:
Window -> jQuery -> cache
Ответить с цитированием
  #5 (permalink)  
Старый 04.05.2011, 08:48
Аватар для x-yuri
Отправить личное сообщение для x-yuri Посмотреть профиль Найти все сообщения от x-yuri
 
Регистрация: 27.12.2008
Сообщений: 4,201

UTSL, там все есть
data: function( elem, name, data, pvt /* Internal Use Only */ ) {
		if ( !jQuery.acceptData( elem ) ) {
			return;
		}

		var internalKey = jQuery.expando, getByName = typeof name === "string", thisCache,

			// We have to handle DOM nodes and JS objects differently because IE6-7
			// can't GC object references properly across the DOM-JS boundary
			isNode = elem.nodeType,

			// Only DOM nodes need the global jQuery cache; JS object data is
			// attached directly to the object so GC can occur automatically
			cache = isNode ? jQuery.cache : elem,

			// Only defining an ID for JS objects if its cache already exists allows
			// the code to shortcut on the same path as a DOM node with no cache
			id = isNode ? elem[ jQuery.expando ] : elem[ jQuery.expando ] && jQuery.expando;

		// Avoid doing any more work than we need to when trying to get data on an
		// object that has no data at all
		if ( (!id || (pvt && id && !cache[ id ][ internalKey ])) && getByName && data === undefined ) {
			return;
		}

		if ( !id ) {
			// Only DOM nodes need a new unique ID for each element since their data
			// ends up in the global cache
			if ( isNode ) {
				elem[ jQuery.expando ] = id = ++jQuery.uuid;
			} else {
				id = jQuery.expando;
			}
		}

		if ( !cache[ id ] ) {
			cache[ id ] = {};

			// TODO: This is a hack for 1.5 ONLY. Avoids exposing jQuery
			// metadata on plain JS objects when the object is serialized using
			// JSON.stringify
			if ( !isNode ) {
				cache[ id ].toJSON = jQuery.noop;
			}
		}

		// An object can be passed to jQuery.data instead of a key/value pair; this gets
		// shallow copied over onto the existing cache
		if ( typeof name === "object" || typeof name === "function" ) {
			if ( pvt ) {
				cache[ id ][ internalKey ] = jQuery.extend(cache[ id ][ internalKey ], name);
			} else {
				cache[ id ] = jQuery.extend(cache[ id ], name);
			}
		}

		thisCache = cache[ id ];

		// Internal jQuery data is stored in a separate object inside the object's data
		// cache in order to avoid key collisions between internal data and user-defined
		// data
		if ( pvt ) {
			if ( !thisCache[ internalKey ] ) {
				thisCache[ internalKey ] = {};
			}

			thisCache = thisCache[ internalKey ];
		}

		if ( data !== undefined ) {
			thisCache[ name ] = data;
		}

		// TODO: This is a hack for 1.5 ONLY. It will be removed in 1.6. Users should
		// not attempt to inspect the internal events object using jQuery.data, as this
		// internal data object is undocumented and subject to change.
		if ( name === "events" && !thisCache[name] ) {
			return thisCache[ internalKey ] && thisCache[ internalKey ].events;
		}

		return getByName ? thisCache[ name ] : thisCache;
	},

http://code.jquery.com/jquery-1.6.js
Ответить с цитированием
Ответ


Опции темы Искать в теме
Искать в теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
как обратиться к childNode по его id в div-е, через id родителя kichSman Events/DOM/Window 5 28.10.2009 02:16
Как получить имя компа через JavaScript? Бурундук Общие вопросы Javascript 3 19.09.2009 16:44
как переписать через attachEvent olgatcpip Internet Explorer 3 13.07.2009 16:30
Данные через сокет по tcp/ip протоколу анна Элементы интерфейса 6 07.07.2009 17:00
Как обновить страницу открытую через post Роберт Общие вопросы Javascript 1 05.11.2008 14:53