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

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值