🏫 Open API_JAVA

[95일차] 코틀린 배열 / 코틀린 컬렉션 / 후기 댓글 수정하기

Dorothy_YANG 2022. 12. 11. 21:28
728x90

20221207(수)

  • 목차
    - 코틀린 배열
    - 코틀린 컬렉션
    - 후기 댓글 수정하기

< 코틀린 배열 >

  • Test2-array.kt
package com.example.androidlab.lab3.test2

// 배열 : Array 클래스를 사용.


fun main() {
    val arr1: Array<Int> = Array(3, {0})
    arr1[0] = 10
    arr1[1] = 20
    arr1.set(2, 30)

    println("${arr1.size}, ${arr1[0]}, ${arr1.get(2)}")

    // 타입유추
    val arr2 = arrayOf<Int>(10, 20, 30)

    // 기초데이타타입에 해당하는 배열클래스
    val arr3: LongArray = LongArray(3, {0L})

}

< 코틀린 컬렉션 >

     ✔ 컬렉션
          List, Set, Map
          ➡ 코틀린은 컬렉션을 muttable(가변) collection vs immutable(불변) collection으로 분류

           1) muttable(가변) collection : 자바와 동일.
           특징? 추가, 변경이 가능

           2) immutable(불변) collection
           특징? 추가, 변경이 불가능

 

  • Test2-collection.kt
package com.example.androidlab.lab3.test2

fun main() {
    // 1) List : immutable(불변) collection
    var list = listOf<Int>(10, 20, 30)
    list.get(0)
    // list.set() 메서드 지원이 안됨.

    // 2) List : mutable(가변) collection
    var list2 = mutableListOf<Int>(10, 20, 30)
    list2.get(0)
    list2.set(1, 30)



    // Map
    var map = mapOf<String, String>(Pair("one","hello"), "two" to "world")

    println(
        """
        map.size : ${map.size}
        map.data : ${map.get("one")}, ${map.get("two")}
        """.trimIndent()
    )

}

 


< 후기 댓글 수정하기 >

 

productDetail.jsp

// 상품후기 수정폼 . review_edit
      $("div#reviewList div#reviewItem").on("click", "button[name='review_edit']", function() {

        $("#btn_review_write").hide();
        $("#btn_review_edit").show();

        let rv_score = $(this).parent().parent().find("input[name='rv_score']").val();
        let rv_num = $(this).data("rv_num");
        let rv_content = $(this).parent().siblings("p").html();

        console.log("별평점 : " + rv_score);
        console.log("상품후기 번호 : " + rv_num);
        console.log("상품후기 내용 : " + rv_content);
      
        $("#rv_content").val(rv_content);

        $("#rv_content").parent().remove("input[name='rv_num']");
        $("#rv_content").parent().append("<input type='text' name='rv_num' value = '" + rv_num + "'>");

        $("#star_rv_score a.rv_score").each(function(index, item){
          if(index < rv_score) {
            $(item).addClass("on");
          }else {
            $(item).removeClass("on");
          }
        });
728x90