天天看點

html data屬性 json,HTML5資料塊JSON(HTML5 Data-block JSON)

HTML5資料塊JSON(HTML5 Data-block JSON)

好的,是以這段代碼:

我正在嘗試使用一些jQuery來完成這樣的事情:

$(".summary-block").data('block', 'pageSize').each(function() {

$('.summary-item').wrap('

$('.col > .summary-item').wrap('

});

現在代碼工作100%,但不是100%就我想要的問題而言。 我怎麼能這樣做:

$(".summary-block").data('block', 'pageSize':4).each(function() {

$('.summary-item').wrap('

$('.col > .summary-item').wrap('

});

請注意:4必須以某種方式包含在我的代碼中。 請幫忙。 謝謝!

Okay so this code:

I'm trying to use some jQuery to accomplish something like this:

$(".summary-block").data('block', 'pageSize').each(function() {

$('.summary-item').wrap('

$('.col > .summary-item').wrap('

});

Now the code works 100%, but not 100% in terms of what I'm trying to ask it. How can I make it so its like:

$(".summary-block").data('block', 'pageSize':4).each(function() {

$('.summary-item').wrap('

$('.col > .summary-item').wrap('

});

Notice the :4 this must be included somehow in my code. Please help. Thanks!

原文:https://stackoverflow.com/questions/12336253

更新時間:2019-08-06 22:51

最滿意答案

你沒有過濾元素,你隻是設定新的data屬性,沒有選擇具有特定data屬性的元素,在你的each函數上下文中你都應該使用this來引用目前元素而不是$('.summary-item')你應該編碼data('block-json') ,而不是data('block') 。 您可以使用filter方法。

...

var $elems = $('.summary-block').filter(function(){

return $(this).data('block-json').pageSize === 4

})

$elems.each(function(){

$('.summary-item', this).wrap('

// or $(this).find('.summary-item')....

})

You don't filter the elements, you are only setting new data attributes, not selecting the elements that have specific data attributes, also in your each function context you should use this which refers to the current element not $('.summary-item') and you should code data('block-json'), not data('block'). You can use filter method.

...

var $elems = $('.summary-block').filter(function(){

return $(this).data('block-json').pageSize === 4

})

$elems.each(function(){

$('.summary-item', this).wrap('

// or $(this).find('.summary-item')....

})

相關問答

将JSON從data屬性中拉出到變量,編輯變量,然後使用更新的變量重新設定屬性。 像這樣的東西應該工作:

// Pull the info from the data-details attribute into a variable called 'details'

var details = JSON.parse($('#car').attr('data-

...

你沒有過濾元素,你隻是設定新的data屬性,沒有選擇具有特定data屬性的元素,在你的each函數上下文中你都應該使用this來引用目前元素而不是$('.summary-item')你應該編碼data('block-json') ,而不是data('block') 。 您可以使用filter方法。

...

我認為釋出的代碼和标題有所不同。 您釋出的代碼是建立一個表(如果不存在)并插入記錄。 但是,由于缺少userid的資料類型,是以建立表行不正确。 嘗試在查詢分析器中運作此sql以查找文法錯誤 'CREATE TABLE IF NOT EXISTS CUSTOMER (id unique, userid, customerdata VARCHAR)'

看看如何使用HTML5 WEb存儲 你可以使用localstorage如下。 if(typeof(Storage) !== "undefined")

...

沒有什麼可以反對你提到的jsedn項目,但它在兩年内沒有看到承諾并且有一些長期存在的問題/公關沒有得到解決:我厭倦了依賴它。 你可以通過建立一個新的clojurescript項目輕松實作你所追求的目标,并且^:export -ing一個解析傳入edn并吐出JS對象的函數(因為沒有充分的理由将edn反序列化,将其序列化為JSON,然後再次反序列化!): (ns app.edn (:require [cljs.reader :as r]))

(defn ^:export read-edn [s]

...

您在代碼中混合對象和字元串。 您的album_content在循環中初始化為對象( {name: item.name, uid: 1} )。 在下一行中,通過附加逗号将其視為字元串。 總體上使用數組來收集所有對象。 使用本機對象(幾乎)總是更好,而不是試圖以某種方式模拟它們。 改為嘗試此代碼。 var albums = '';

var album_list = [];

$.each(data, function(i,item){

var name = item.name;

album

...

我會使用Felix Kling的JSONP方法。 将資料檔案包裝在回調函數中: (function(data) {

// Do things with your data object here

})(

// Put your data object here as the argument to the callback

);

當您将此腳本檔案包含在标記中時,将自動執行回調函數。 I would use Felix Kling's approach with JSONP. Wrap y

...