자바 스크립트에서 정렬를 하기 위해서는 sort() 함수를 이용한다.


1. 숫자 정렬


예를 들어 


var a = [33,4, 111, 22]

a.sort()

결과 : [111, 22, 33, 4]



위와 같이 기본적으로는 알파벳으로 정렬한다.


숫자로 정렬하고자 하면 아래와 같이 sort 함수의 function을 인자로 넘겨준다.


a.sort(function(a,b){

      return a-b;

});

결과 : [4, 22, 33, 111]


이유는 첫번째 인자가 두번째 인자보다 앞에 나타나야 한다면 0보다 작은 숫자

아니면 0보다 큰 숫자를 리턴하면 된다고 한다.


두 값이 동등하다면(순서가 무의미 하다면) 0 을 리턴해야 한다.



그럼 역순으로 정렬하고자 하면

a.sort(function(a,b){

      return b-a;

});


이다. 



2. 문자 정렬


만약 대소문자 구분 안하고 정렬하고 싶다면 모든 문자를 임시로 소문자나, 대문자를 만들어서 작업하면 된다.

그냥 정렬일 경우


var a = ['ant', 'Bug', 'cat', 'Dog']

a.sort()

결과 : ["Bug", "Dog", "ant", "cat"]



대소문자 구분안함.


a.sort(function(s, t){

var a = s.toLowerCase();

var b = t.toLowerCase();

if(a<b) return -1;

if(a>b) return 1;

return 0;

});


결과 : ["ant", "Bug", "cat", "Dog"]


위와 같이 적용할 수 있다.




'WEB > javascript' 카테고리의 다른 글

자바 스크립트 상속 구조  (0) 2014.07.05
json 변환  (0) 2014.06.05

* codecademy 간단한 웹 페이지 구성하는 방법


index.html



<!DOCTYPE html>

<html>


  <head>

    <link href="http://s3.amazonaws.com/codecademy-content/courses/ltp/css/shift.css" rel="stylesheet">

    

    <link rel="stylesheet" href="http://s3.amazonaws.com/codecademy-content/courses/ltp/css/bootstrap.css">

    <link rel="stylesheet" href="main.css">

    

  </head>


  <body>

    <div class="nav">

      <div class="container">

        <ul class="pull-left">

          <li><a href="#">Name</a></li>

          <li><a href="#">Browse</a></li>

        </ul>

        <ul class="pull-right">

          <li><a href="#">Sign Up</a></li>

          <li><a href="#">Log In</a></li>

          <li><a href="#">Help</a></li>

        </ul>

      </div>

    </div>


    <div class="jumbotron">

      <div class="container">

        <h1>Find a place to stay.</h1>

        <p>Rent from people in over 34,000 cities and 192 countries.</p>

        <a href="#">Learn More</a>

      </div>

    </div> 

    <div class="neighborhood-guides">

        <div class="container"> 

            <h2> Neighborhood Guides </h2>

            <p> Not sure where to stay? We've created neighborhood guides for cities all around the world. </p>

            

            <div class="row">

                <div class="col-md-4"> 

                    <div class="thumbnail">

                        <img src="http://goo.gl/0sX3jq" >

                    </div>

                    

                    <div class="thumbnail">

                        <img src="http://goo.gl/an2HXY" >

                    </div>

                </div>

                <div class="col-md-4">

                    <div class="thumbnail">

                        <img src="http://goo.gl/Av1pac" >

                    </div>

                    <div class="thumbnail">

                        <img src="http://goo.gl/vw43v1" >

                    </div>

                    

                </div>

                <div class="col-md-4"> 

                    <div class="thumbnail">

                        <img src="http://goo.gl/0Kd7UO" >

                    </div>

                </div>

            </div>

        </div>

        

    

    </div>


    <div class="learn-more">

 <div class="container">

<div class="row">

     <div class="col-md-4">

<h3>Travel</h3>

<p>From apartments and rooms to treehouses and boats: stay in unique spaces in 192 countries.</p>

<p><a href="#">See how to travel on Airbnb</a></p>

     </div>

 <div class="col-md-4">

<h3>Host</h3>

<p>Renting out your unused space could pay your bills or fund your next vacation.</p>

<p><a href="#">Learn more about hosting</a></p>

 </div>

 <div class="col-md-4">

<h3>Trust and Safety</h3>

<p>From Verified ID to our worldwide customer support team, we've got your back.</p>

<p><a href="#">Learn about trust at Airbnb</a></p>

 </div>

   </div>

 </div>

</div>

  </body>

</html>




main.css




.nav a {

  color: #5a5a5a;

  font-size: 11px;

  font-weight: bold;

  padding: 14px 10px;

  text-transform: uppercase;

}


.nav li {

  display: inline;

}


.jumbotron {

  background-image:url('http://goo.gl/04j7Nn');

  height: 500px;

}


.jumbotron .container {

  position: relative;

  top:100px;

}


.jumbotron h1 {

  color: #fff;

  font-size: 48px;  

  font-family: 'Shift', sans-serif;

  font-weight: bold;

}


.jumbotron p {

  font-size: 20px;

  color: #fff;

}


.learn-more {

  background-color: #f7f7f7;

}


.learn-more h3 {

  font-family: 'Shift', sans-serif;

  font-size: 18px;

  font-weight: bold;

}


.learn-more a {

  color: #00b0ff;

}


.neighborhood-guides{

    background-color : #efefef;

    border-bottom : 1px solid #dbdbdb;

    

}


.neighborhood-guides h2{

    color : #393c3d;

    font-size : 24px;

}


.neighborhood-guides p{

    font-size : 15px;

    margin-bottom : 13px;

}

'WEB > 트위터부트스트랩' 카테고리의 다른 글

[트위터부트스트랩] 테마 모음 사이트  (0) 2014.01.21

// original classes

function Animal(name, numLegs) {

    this.name = name;

    this.numLegs = numLegs;

    this.isAlive = true;

}

function Penguin(name) {

    this.name = name;

    this.numLegs = 2;

}

function Emperor(name) {

    this.name = name;

    this.saying = "Waddle waddle";

}


// set up the prototype chain

Penguin.prototype = new Animal();

Emperor.prototype = new Penguin();


var myEmperor = new Emperor("Jules");


console.log( myEmperor.saying ); // should print "Waddle waddle"

console.log( myEmperor.numLegs ); // should print 2

console.log( myEmperor.isAlive ); // should print true

'WEB > javascript' 카테고리의 다른 글

[javascript] 정렬하기  (0) 2014.08.01
json 변환  (0) 2014.06.05

array를 json으로 변경


JSON.stringify(Array);

'WEB > javascript' 카테고리의 다른 글

[javascript] 정렬하기  (0) 2014.08.01
자바 스크립트 상속 구조  (0) 2014.07.05

js 문법을 체크해준다.






특정 경고를 무시할 때는 아래와 같이 해준다.

/* jshint ignore:start */

function a(){

}

/* jshint ignore:end */





특정 라인만 무시할려면 아래와 같이 해준다.


// jshint ignore:line




자세한 설명은 아래 링크 참고


사이트 : http://www.jshint.com/

옵션 : http://blog.outsider.ne.kr/1007



기본적인  angluarjs 옵션들.


{

  "curly": true,

  "eqeqeq": true,

  "immed": true,

  "latedef": true,

  "newcap": true,

  "noarg": true,

  "sub": true,

  "undef": true,

  "unused": true,

  "boss": true,

  "eqnull": true,

  "multistr": true,

  "node": true,

  "predef": [

    "suite",

    "setup",

    "test",

    "angular",

    "describe",

    "beforeEach",

    "inject",

    "it",

    "expect"

  ]

}


'WEB > 프론트 개발환경' 카테고리의 다른 글

Grunt 설정  (0) 2014.03.15
개발환경 셋팅  (0) 2014.03.15
자바 스크립트 기술기반  (0) 2014.03.15

* rev : 이름 변경


// Renames files for browser caching purposes

        rev: {

            dist: {

                files: {

                    src: [

                        '<%= config.dist %>/scripts/{,*/}*.js',

                        '<%= config.dist %>/styles/{,*/}*.css',

                        '<%= config.dist %>/images/{,*/}*.*',

                        '<%= config.dist %>/styles/fonts/{,*/}*.*',

                        '<%= config.dist %>/*.{ico,png}'

                    ]

                }

            }

        },


: .


* cssmin, uglify : 파일명을 주어 원하는 이름으로 빌드 되도록 한다.


cssmin: {

            dist: {

                files: {

                    '<%= config.dist %>/styles/rest-min.css': [

                        '.tmp/styles/{,*/}*.css',

                        '<%= config.app %>/styles/{,*/}*.css'

                    ]

                }

            }

        },

        uglify: {

            dist: {

                files: {

                    '<%= config.dist %>/scripts/rest-min.js': [

                        // '<%= config.dist %>/scripts/scripts.js'

                        '<%= config.app %>/scripts/{,*/}*.js'

                    ]

                }

            }

        },

        concat: {

            dist: {}

        },




'WEB > 프론트 개발환경' 카테고리의 다른 글

jshint  (0) 2014.03.15
개발환경 셋팅  (0) 2014.03.15
자바 스크립트 기술기반  (0) 2014.03.15
개발환경 구성을 Yeoman을 통해 구성한다.

* yo - the scaffolding tool from Yeoman
* bower - the package management tool
* grunt - the build tool

* Nodejs 설치

: 노드 기반 패키지

- http://www.nodejs.org/

- 설치 후 환경 변수 추가!



* Git 설치

: 패키지를 git에서 가져오는 경우도 있음.

http://git-scm.com/

- 설치 후 환경 변수 추가!


* Ruby on rails 설치

: 프로그램 구현을 루비로도 구성되어 있음.

http://rubyonrails.org/download

- 설치 후 환경 변수 추가!


* Yeoman 설치 

: 손쉬운 자바 스크립트 개발 환경 설치

: yo + bower + grunt

http://yeoman.io/gettingstarted.html

: 위 사이트를 참고하여 설치한다.



git 패키지 내려받기 후 작업 리스트


1. grunt 설치

npm install -g grunt


2. grunt 설치

npm install -g grunt-cli


3. grunt 설치

npm install grunt


4. 모든 패키지 설치

npm install


5. bower 설치

npm install -g bower


6. bower 패키지 설치

bower install


7. grunt 빌드

grunt build


8. 서버 키기

grunt server

'WEB > 프론트 개발환경' 카테고리의 다른 글

jshint  (0) 2014.03.15
Grunt 설정  (0) 2014.03.15
자바 스크립트 기술기반  (0) 2014.03.15

Yeoman :

http://yeoman.io/


yo + bower + grunt  조합으로 손쉽게 개발환경을 꾸밀수 있도록 해준다.



이번 개인적인 프로젝트는


Yeoman : yo + bower + grunt 환경에


sublime text2 : 개발 도구


angularjs : js 프레임워크


twitter bootstrap : ui 프레임워크


이런 기술 기반으로 시작해보자!


회사외 업무를 진행하느라 어려움이 많겠지만 해보고 싶은거 다 해보자!

'WEB > 프론트 개발환경' 카테고리의 다른 글

jshint  (0) 2014.03.15
Grunt 설정  (0) 2014.03.15
개발환경 셋팅  (0) 2014.03.15

http://troy.labs.daum.net/


다음에서 만들었나 보네요

datatype: "local" 인 상황에서

데이터를 넣는 방식이 아래와 같았다.


function setJqGrid(gridId, json, maxLine){

$(gridId).clearGridData();  // 이전 데이터 삭제

if(json.length>0){

for(var i=0; i<json.length; i++){

jQuery(gridId).jqGrid('addRowData',i+1,json[i]);

if(maxLine < i){

break;

}

}

}

}



그랬더니 엄청 느리네 ??



그래서 아래와 같이 변경하였다.


function setJqGrid(gridId, json, maxLine){

$(gridId).clearGridData();  // 이전 데이터 삭제

if(json.length>0){

jQuery(gridId).jqGrid('setGridParam',

       { 

           datatype: 'local',

           data:json

       })

   .trigger("reloadGrid");

}

}



속도 개선이 확 되었다.

결론 : jqGrid는 그렇게 느리지 않다.


'WEB > jqGrid' 카테고리의 다른 글

[jqGrid] 함수  (0) 2014.01.19
[jqGrid] 정렬 기능 정리  (0) 2014.01.19

+ Recent posts