IIssNan's Notes

Quick notes


  • 首页

  • 归档

  • 标签

  • 搜索

jQuery Mockjax

发表于 2013-02-01 | | 阅读次数

jQuery Mockjax用于模拟Ajax请求数据,以解决Server API未就绪时的前端开发阻塞问题。

假设前端发起一个/test/inline API的请求:

$.ajax({
    url: '/test/inline',
    dataType: 'json',
    success: function(json) {
        alert('You said: ' + json.say);
    }
});

假若API同时在开发当中,此时可以使用jQuery Mockjax来模拟API:

$.mockjax({
    url: '/test/inline',
    dataType: 'json',
    responseTime: 2500,
    responseText: {
        say: 'Hello world!'
    }
});

项目地址:

  • jQuery.mockjax

NPM package.json里的注释

发表于 2013-01-25 | | 阅读次数

使用//作为键值即可:

{
    "//": "comment"
}

多行注释有两种写法:

"//": "第一种",
"//": "something more"

"//": "第二种"
"//": ["comment", "something more"]

完整示例:

{
    "name": "CountDown",
    "version": "0.0.1",
    "//": "All dependencies MUST be Compatible with Grunt 0.4",
    "devDependencies": {
        "grunt": "~0.4.0",
        "grunt-contrib-jshint": "~0.1.1",
        "grunt-contrib-jasmine": "~0.3.0",
        "grunt-contrib-uglify": "~0.1.1"
    }
}

参考资料:

  • How do I add comments to package.json for npm install? - StackOverflow
  • Node.js mailing list

如何删除 Github 上的项目的某一个 commit?

发表于 2013-01-17 | | 阅读次数

如果不小心将账户密码或者私钥信息提交到了 Github 上,应该怎么删除那个提交呢?需要以下步骤:

  1. 首先,在本地仓库中移除这个提交,可以使用 git rebase -i 命令。如果带有重要信息的提交是最后一个提交,那么可以使用:

    1
    git rebase -i HEAD~2

    删除掉对应的提交后保存退出。

  2. 强制更新 Github上 的分支,有两种方法:

    1
    2
    git push origin +master # 方法一,使用+强制更新
    git push -f origin HEAD^:master # 方法二,使用-f参数

参考:

  • How do remove a commit on Github?

Grunt

发表于 2013-01-17 | | 阅读次数

Grunt is a task-based command line build tool for JavaScript projects


Project @ Github

Break $.each loop

发表于 2013-01-13 | | 阅读次数

結束 jQuery.each 的循環是通過設定 jQuery.each 的 callback 函數中返回 false;
而繼續下一個循環(即 continue ),是 return 非 false 值。亦適用於 .each。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
(function(){
// 結束循環(即break)
jQuery.each(aOptionList, function(index, option){
if (option.innerHTML === "stop") {
return false; // 返回false即break掉each循環
}
// magic
});
// 繼續下一個循環(即continue)
jQuery.each(aOptionList, function(index, option){
if (option.innerHTML === "stop") {
return "continue"; // 返回任意非false值
}
// magic
});
}());

官方說明:

We can break the $.each() loop at a particular iteration by making the callback function return false. Returning non-false is the same as a continue statement in a for loop; it will skip immediately to the next iteration.

参考资料:

  • jQuery.each API
1…232425…37
IIssNan

IIssNan

胡编一通,乱写一气

183 日志
6 分类
111 标签
RSS
GitHub Twitter 豆瓣 知乎
© 2011 - 2017 IIssNan
由 Hexo 强力驱动
主题 - NexT.Pisces
0%