[jQuery] $.map, $.each, detach() , $.getJSOIN()
$.map function will return the modifies array.
$.each function will not new a new array, the old value will still be the same.
detach() funciton will remove the element from the DOM, you can append those element later, it works more eiffient.
getJSON
$('button').on('click', function() {
$.getJSON('/cities/deals', function(result){
$.each(result, function(index, dealItem) {
var dealElement = $('.deal-' + index);
dealElement.find('.name').html(dealItem.name);
dealElement.find('.price').html(dealItem.price);
});
});
});
Let's take a minute to make our previous code a bit more efficient. Use the .detach() method to remove the .flight-times list element from the DOM before you insert the new listitems. Then, re-insert the .flight-times element back into the .flights element.
$('.update-available-flights').on('click', function() {
$.getJSON('/flights/late', function(result) {
var flightElements = $.map(result, function(flightItem, index){
var flightEl = $('<li>'+flightItem.flightNumber+'-'+flightItem.time+'</li>');
return flightEl;
});
$('.flight-times').detach().html(flightElements).appendTo('.flights');
});
});
[jQuery] $.map, $.each, detach() , $.getJSOIN()的更多相关文章
- 冰冻三尺非一日之寒--jQuery
第十七章 jQuery http://jquery.cuishifeng.cn/ 一.过滤选择器: 目的:处理更复杂的选择,是jQuery自定义的,不是CSS3中的选择器. ...
- map
说明 map()是python的内置函数. 定义:接收2个参数,第一个参数一般为方法:第二个参数为可迭代对象,此方法会自动迭代第二个参数,然后将获取的数据传入第一个参数. 案例操作 需求:将下面的数据 ...
- BeanUtils.populate(obj, map);
public static void populate(Object bean, Map<String, ? extends Object> properties) throws Ille ...
- 进击的Python【第十七章】:jQuery的基本应用
进击的Python[第十七章]:jQuery的基本应用
- spring4mvc返回json(bean,list,map)
因为spring3和spring4的mvc在前端返回json所需要的jar包不一样,所以索性写一篇关于spring4mvc在前端返回json的博文. 首先,新建一个web项目,项目格式如图所示: co ...
- 网页设计之jQuery
1.在html中引入css和jQuery <!DOCTYPE html> <html lang="en"> <head> <meta ch ...
- Python之Web前端Dom, jQuery
Python之Web前端: Dom jQuery ###Dom 一. 什么是Dom? 文档对象模型(Document Object Model,DOM)是一种用于HTML和XML文档的编程接口.它 ...
- [Java] Java解析XML格式Response后组装成Map
//Get and Parse Response def response = context.expand(‘${TestStepName#Response}’) def xmlParser = n ...
- vue-cli webpack 引入jquery
首先在package.json里的dependencies加入"jquery" : "^2.2.3",然后install 在webpack.base.conf. ...
- 【dom4j】解析xml为map
dom4j解析xml文件 <?xml version="1.0" encoding="utf-8"?> <workflows> < ...
随机推荐
- 1265. [NOIP2012] 同余方程
1265. [NOIP2012] 同余方程 ★☆ 输入文件:mod.in 输出文件:mod.out 简单对比 时间限制:1 s 内存限制:128 MB [题目描述] 求关于 x 的同余 ...
- BZOJ 5059: 前鬼后鬼的守护 可并堆 左偏树 数学
https://www.lydsy.com/JudgeOnline/problem.php?id=5059 题意:将原序列{ai}改为一个递增序列{ai1}并且使得abs(ai-ai1)的和最小. 如 ...
- Codeforces Round #248 (Div. 1) A. Ryouko's Memory Note 水题
A. Ryouko's Memory Note 题目连接: http://www.codeforces.com/contest/434/problem/A Description Ryouko is ...
- hierarchyid有关的一些函数
于hierarchyid有关的一些函数主要有: GetAncestor :取得某一个级别的祖先 GetDescendant :取得某一个级别的子代 GetLevel :取得级别 ...
- [Visual Studio] 重置默认设置 还原默认设置
恢复默认设置的2种方法 如果VS出现问题或设置变乱,可以通过恢复默认设置使之回到安装成功时的状态,从而解决出现的问题.VS恢复默认设置的方法有2种,分别是:通过“导入和导出设置”实现和通过命令实现. ...
- elasticsearch实例讲解增删改查
1.首先弄明白四个概念 elasticsearch 关系型数据库 index 数据库 type 表 document 行 field 字段 如果刚一开始理解比较困难,那你就在心中默念100遍,10遍也 ...
- MySQL Innodb 存储引擎学习篇
master thread的县城优先级别最高.其内部由几个循环(loop)组成:主循环(loop).后台循环(background loop).刷新循环(flush loop).暂停循环(suspen ...
- Bus Blaster
http://dangerousprototypes.com/docs/Bus_Blaster Bus Blaster v2 is an experimental, high-speed JTAG d ...
- Error creating bean with name 'adminUserController': Injection of autowired dependencies failed;
spring 个坑爹地,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ...
- git diff 打补丁
[root@workstation2017 demo]# git diff old new >cc.diff[root@workstation2017 demo]# cat cc.diffdif ...