-1

単一ページのアンケートアプリを作成していますが、質問の配列を作成する正しい方法がわかりません。また、このように質問の種類を混ぜることは悪い習慣ですか?(単一の選択肢、同じ配列の複数の選択肢?)基本的に、私はまだ私が見た2つの基本的なアプローチの長所/短所を理解しようとしています。

オプション1:

var hygiene = [

  {
    pageheader: "Self-Care"
  }

  {
    q: "When was your last shower?",
    choicetype: "radio",
    a1: "Today",
    a2: "Yesterday",
    a3: "Two days ago",
    a4: "I don't know"
  }

  {
    q: "How much do you weigh today?",
    choicetype: "keypad"
  }

  {
    q: "Do you take any medications?",
    choicetype: "radio",
    a1: "Yes",
    a2: "No"
  }

  {
    q: "Which medications?",
    choicetype: "multiselect",
    a1: "Zostavax",
    a2: "Percocet",
    a3: "Actemra",
    a4: "Cimzia",
    a5: "Relprevv"
  }

];

オプション2:

var hygiene = {

  pageheader: "Self-Care",

  question1: [
    "When was your last shower?", "radio", "Today", "Yesterday",
    "Two days ago", "I don't know"
  ],

  question2: [
    "How much do you weigh today?", "keypad"
  ],

  question3: [
    "Do you take any medications?", "radio", "Yes", "No"
  ],

  question4: [
    "Which medications?", "multiselect", "Zostavax", "Percocet",
    "Actemra", "Cimzia", "Relprevv"
  ]

};
4

2 に答える 2

7

どちらも使用しないことをお勧めしますが、次のことをお勧めします。

var hygiene = {

    pageheader: "Self-Care",

    questions: [

        {
            question: "When was your last shower?",
            choicetype: "radio",
            answers: [
                "Today",
                "Yesterday",
                "Two days ago",
                "I don't know"
            ]
        },

        {
            question: "How much do you weigh today?",
            choicetype: "keypad"
        },

        {
            question: "Do you take any medications?",
            choicetype: "radio",
            answers: [
                "Yes",
                "No"
            ]
        },

        {
            question: "Which medications?",
            choicetype: "multiselect",
            answers: [
                "Zostavax",
                "Percocet",
                "Actemra",
                "Cimzia",
                "Relprevv"
             ]
         }
    ]
}
于 2012-11-14T21:21:10.943 に答える
1

オプション 1 はオプション 2 よりもはるかに優れています。変数を指定し、各文字列に意味のある名前を付けて、後でコードで使用できるようにするためです。

大量のアンケートがあった場合、後でコードが読みやすくなるかどうかによって異なります。ファイルにこれらが 100 個ある場合、1 個と 2 個のどちらが好みですか?

于 2012-11-14T21:16:21.173 に答える