2017-12-16 11 views
-3

私はこのコードを持っている:jQueryで不合理なエラーが発生しましたか?

var buggy_brand_name = ['Baby Jogger', 'Babyzen', 'Bugaboo', 'GB', 'Icandy', 'Joie', 'Maclaren', 'Mamas&Papas', 'Maxi cosi', 'Mountain Buggy', "Out 'N' About", 'Phil and Teds', 
'Quinny', 'Silver Cross', 'Stokke', 'UppaBaby']; 
var multi_model = [['City Elite', 'City Lite', 'City Mini', 'City Mini GT', 'City Mini ZIP', 'City Select', 'City Versa GT', 'City Vue', 'Summit X3'], 
    ['Yoyo+', 'Zen'], 
    ['Buffalo', 'Cameleon3', 'Bee +', 'Bee 3', 'Bee 5', 'Donkey'], 
    ['Pockit'], 
    ['Peach Pushchair', 'Peach Pushchair and Carrycot', 'Peach All Teraine Pushchair and Carrycot', 'Peach All Teraine Pushchair', 'Apple Pushchair', 
    'Apple 2 Pear Pushchair (Double)', 'Strawberry Pushchair', 'Strawberry Style Collection Pushchair', 'Strawberry 2 Pushchair'], 
    ['Nitro'], 
    ['Techno XLR', 'Techno XT', 'Quest', 'Triumph'], 
    ['Armadillo', 'Voyage', 'Zoom', 'Ocarro'], 
    ['Elea', 'Mura', 'Stella', 'Nova', 'Dana'], 
    ['Nano', 'Urban', 'Terrain', 'Duet', 'Swift', 'Mini'], 
    ['Nipper', 'Sport Nipper', 'Nipper Double', 'Nipper 360'], 
    ['Dot', 'Smart', 'Sport ', 'Dash', 'Mod', 'Voyager', 'Lux', 'Verve'], 
    ['Moodd', 'Buzz', 'Zapp'], 
    ['Pioneer', 'Wayfarer ', 'Zest', 'Pop', 'Reflex'], 
    ['Xplory', 'Scoot', 'Trailz'], 
    ['Cruz 2017', 'UppaBaby Vista', 'UppaBaby G-Luxe']]; 
for(var i = 0; i < buggy_brand_name.length; i++) { 
$('#brand').append('<option value="' + buggy_brand_name[i] + '">' + buggy_brand_name[i] + '</option>'); 

$('#brand').on('change', function() { 
$('#model_fieldset').css({display: 'block'}); 
    var brand = $('#brand').val(); 
    var model = $('#model'); 
    switch (brand) 
    { 
    case 'Baby Jogger': 
     $('.sell-model').remove(); 
     for (var i = 0; i < multi_model[0][i].length; i++) { 
     model.append('<option class="sell-model" value="' + multi_model[0][i] + '">' +multi_model[0][i] + '</option>'); 
     } 
     break; 
    case 'Babyzen': 
     $('.sell-model').remove(); 
     for (var i = 0; i < multi_model[1][i].length; i++) { 
     model.append('<option class="sell-model" value="' + multi_model[1][i] + '">' +multi_model[1][i] + '</option>'); 
     } 
     break; 
    case 'Bugaboo': 
     $('.sell-model').remove(); 
     for (var i = 0; i < multi_model[2][i].length; i++) { 
     model.append('<option class="sell-model" value="' + multi_model[2][i] + '">' +multi_model[2][i] + '</option>'); 
     } 
     break; 
    case 'GB': 
     $('.sell-model').remove(); 
     for (var i = 0; i < multi_model[3][i].length; i++) { 
     model.append('<option class="sell-model" value="' + multi_model[3][i] + '">' +multi_model[3][i] + '</option>'); 
     } 
     break; 
    case 'Icandy': 
     $('.sell-model').remove(); 
     for (var i = 0; i < multi_model[4][i].length; i++) { 
     model.append('<option class="sell-model" value="' + multi_model[4][i] + '">' +multi_model[4][i] + '</option>'); 
     } 
     break; 
    case 'Joie': 
     $('.sell-model').remove(); 
     for (var i = 0; i < multi_model[5][i].length; i++) { 
     model.append('<option class="sell-model" value="' + multi_model[5][i] + '">' +multi_model[5][i] + '</option>'); 
     } 
     break; 
    case 'Maclaren': 
     $('.sell-model').remove(); 
     for (var i = 0; i < multi_model[6][i].length; i++) { 
     model.append('<option class="sell-model" value="' + multi_model[6][i] + '">' +multi_model[6][i] + '</option>'); 
     } 
     break; 
    case 'Mamas&Papas': 
     $('.sell-model').remove(); 
     for (var i = 0; i < multi_model[7][i].length; i++) { 
     model.append('<option class="sell-model" value="' + multi_model[7][i] + '">' +multi_model[7][i] + '</option>'); 
     } 
     break; 
    case 'Maxi cosi': 
     $('.sell-model').remove(); 
     for (var i = 0; i < multi_model[8][i].length; i++) { 
     model.append('<option class="sell-model" value="' + multi_model[8][i] + '">' +multi_model[8][i] + '</option>'); 
     } 
     break; 
    case 'Mountain Buggy': 
     $('.sell-model').remove(); 
     for (var i = 0; i < multi_model[9][i].length; i++) { 
     model.append('<option class="sell-model" value="' + multi_model[9][i] + '">' +multi_model[9][i] + '</option>'); 
     } 
     break; 
    case "Out 'N' About": 
     $('.sell-model').remove(); 
     for (var i = 0; i < multi_model[10][i].length; i++) { 
     model.append('<option class="sell-model" value="' + multi_model[10][i] + '">' +multi_model[10][i] + '</option>'); 
     } 
     break; 
    case 'Phil and Teds': 
     $('.sell-model').remove(); 
     for (var i = 0; i < multi_model[11][i].length; i++) { 
     model.append('<option class="sell-model" value="' + multi_model[11][i] + '">' +multi_model[11][i] + '</option>'); 
     } 
     break; 
    case 'Quinny': 
     $('.sell-model').remove(); 
     for (var i = 0; i < multi_model[12][i].length; i++) { 
     model.append('<option class="sell-model" value="' + multi_model[12][i] + '">' +multi_model[12][i] + '</option>'); 
     } 
     break; 
    case 'Silver Cross': 
     $('.sell-model').remove(); 
     for (var i = 0; i < multi_model[13][i].length; i++) { 
     model.append('<option class="sell-model" value="' + multi_model[13][i] + '">' +multi_model[13][i] + '</option>'); 
     } 
     break; 
    case 'Stokke': 
     $('.sell-model').remove(); 
     for (var i = 0; i < multi_model[14][i].length; i++) { 
     model.append('<option class="sell-model" value="' + multi_model[14][i] + '">' +multi_model[14][i] + '</option>'); 
     } 
     break; 
    case 'UppaBaby': 
     $('.sell-model').remove(); 
     for (var i = 0; i < multi_model[15][i].length; i++) { 
     model.append('<option class="sell-model" value="' + multi_model[15][i] + '">' +multi_model[15][i] + '</option>'); 
     } 
     break; 
    }; 

すべてが働いているが、私はこれらのエラーを取得:

sybg_js_1.js:75 Uncaught TypeError: Cannot read property 'length' of undefined
at HTMLSelectElement. (sybg_js_1.js:75)
at HTMLSelectElement.dispatch (jquery-3.2.1.min.js:3)
at HTMLSelectElement.q.handle (jquery-3.2.1.min.js:3)

(anonymous) @ sybg_js_1.js:75
dispatch @ jquery-3.2.1.min.js:3
q.handle @ jquery-3.2.1.min.js:3

sybg_js_1.js:81 Uncaught TypeError: Cannot read property 'length' of undefined

at HTMLSelectElement. (sybg_js_1.js:81)
at HTMLSelectElement.dispatch (jquery-3.2.1.min.js:3) at HTMLSelectElement.q.handle (jquery-3.2.1.min.js:3) (anonymous) @ sybg_js_1.js:81 dispatch @ jquery-3.2.1.min.js:3 q.handle @ jquery-3.2.1.min.js:3 sybg_js_1.js:99 Uncaught TypeError: Cannot read property 'length' of ndefined at HTMLSelectElement. (sybg_js_1.js:99) at HTMLSelectElement.dispatch (jquery-3.2.1.min.js:3) at HTMLSelectElement.q.handle (jquery-3.2.1.min.js:3) (anonymous) @ sybg_js_1.js:99 dispatch @ jquery-3.2.1.min.js:3 q.handle @ jquery-3.2.1.min.js:3 sybg_js_1.js:105 Uncaught TypeError: Cannot read property 'length' of undefined at HTMLSelectElement. (sybg_js_1.js:105) at HTMLSelectElement.dispatch (jquery-3.2.1.min.js:3) at HTMLSelectElement.q.handle (jquery-3.2.1.min.js:3) (anonymous) @ sybg_js_1.js:105 dispatch @ jquery-3.2.1.min.js:3 q.handle @ jquery-3.2.1.min.js:3 sybg_js_1.js:147 Uncaught TypeError: Cannot read property 'length' of undefined at HTMLSelectElement. (sybg_js_1.js:147) at HTMLSelectElement.dispatch (jquery-3.2.1.min.js:3) at HTMLSelectElement.q.handle (jquery-3.2.1.min.js:3) (anonymous) @ sybg_js_1.js:147 dispatch @ jquery-3.2.1.min.js:3 q.handle @ jquery-3.2.1.min.js:3 sybg_js_1.js:75 Uncaught TypeError: Cannot read property 'length' of undefined at HTMLSelectElement. (sybg_js_1.js:75) at HTMLSelectElement.dispatch (jquery-3.2.1.min.js:3) at HTMLSelectElement.q.handle (jquery-3.2.1.min.js:3) (anonymous) @ sybg_js_1.js:75 dispatch @ jquery-3.2.1.min.js:3 q.handle @ jquery-3.2.1.min.js:3 sybg_js_1.js:81 Uncaught TypeError: Cannot read property 'length' of undefined at HTMLSelectElement. (sybg_js_1.js:81) at HTMLSelectElement.dispatch (jquery-3.2.1.min.js:3) at HTMLSelectElement.q.handle (jquery-3.2.1.min.js:3) (anonymous) @ sybg_js_1.js:81 dispatch @ jquery-3.2.1.min.js:3 q.handle @ jquery-3.2.1.min.js:3 sybg_js_1.js:87 Uncaught TypeError: Cannot read property 'length' of undefined at HTMLSelectElement. (sybg_js_1.js:87) at HTMLSelectElement.dispatch (jquery-3.2.1.min.js:3) at HTMLSelectElement.q.handle (jquery-3.2.1.min.js:3) (anonymous) @ sybg_js_1.js:87 dispatch @ jquery-3.2.1.min.js:3 q.handle @ jquery-3.2.1.min.js:3 sybg_js_1.js:93 Uncaught TypeError: Cannot read property 'length' of undefined at HTMLSelectElement. (sybg_js_1.js:93) at HTMLSelectElement.dispatch (jquery-3.2.1.min.js:3) at HTMLSelectElement.q.handle (jquery-3.2.1.min.js:3) (anonymous) @ sybg_js_1.js:93 dispatch @ jquery-3.2.1.min.js:3 q.handle @ jquery-3.2.1.min.js:3 sybg_js_1.js:99 Uncaught TypeError: Cannot read property 'length' of undefined at HTMLSelectElement. (sybg_js_1.js:99) at HTMLSelectElement.dispatch (jquery-3.2.1.min.js:3) at HTMLSelectElement.q.handle (jquery-3.2.1.min.js:3) (anonymous) @ sybg_js_1.js:99 dispatch @ jquery-3.2.1.min.js:3 q.handle @ jquery-3.2.1.min.js:3 sybg_js_1.js:105 Uncaught TypeError: Cannot read property 'length' of undefined at HTMLSelectElement. (sybg_js_1.js:105) at HTMLSelectElement.dispatch (jquery-3.2.1.min.js:3) at HTMLSelectElement.q.handle (jquery-3.2.1.min.js:3) (anonymous) @ sybg_js_1.js:105 dispatch @ jquery-3.2.1.min.js:3 q.handle @ jquery-3.2.1.min.js:3 sybg_js_1.js:111 Uncaught TypeError: Cannot read property 'length' of undefined at HTMLSelectElement. (sybg_js_1.js:111) at HTMLSelectElement.dispatch (jquery-3.2.1.min.js:3) at HTMLSelectElement.q.handle (jquery-3.2.1.min.js:3) (anonymous) @ sybg_js_1.js:111 dispatch @ jquery-3.2.1.min.js:3 q.handle @ jquery-3.2.1.min.js:3 sybg_js_1.js:117 Uncaught TypeError: Cannot read property 'length' of undefined at HTMLSelectElement. (sybg_js_1.js:117) at HTMLSelectElement.dispatch (jquery-3.2.1.min.js:3) at HTMLSelectElement.q.handle (jquery-3.2.1.min.js:3) (anonymous) @ sybg_js_1.js:117 dispatch @ jquery-3.2.1.min.js:3 q.handle @ jquery-3.2.1.min.js:3 sybg_js_1.js:165 Uncaught TypeError: Cannot read property 'length' of undefined at HTMLSelectElement. (sybg_js_1.js:165) at HTMLSelectElement.dispatch (jquery-3.2.1.min.js:3) at HTMLSelectElement.q.handle (jquery-3.2.1.min.js:3) (anonymous) @ sybg_js_1.js:165 dispatch @ jquery-3.2.1.min.js:3 q.handle @ jquery-3.2.1.min.js:3

いずれかが理由を知っていますか?

+3

コードの最も不合理な部分は、コードの再利用の欠如です。 –

+0

長さの代わりにlength()を試しましたか? –

+0

.lenghtは関数ではありません –

答えて

0

multi_model[10][i].lengthmulti_model[10].length(10の代わりにそれぞれのインデックス)に交換したい場合は、

ループ条件には、特定の要素の長さがmulti_modelに必要です。 multi_model要素は配列そのものですが、それ以上配列はなく文字列を含んでいます。

特に条件i < multi_model[0][i].lengthは、ここでは何かが論理的ではないと思うはずです。

幸運を祈る!

関連する問題