2012-09-16 4 views
0

broken 데모 : http://jsfiddle.net/sTzCS/52/jQuery : 왜이 ​​경고가 발생하지 않습니까?

피들 (fiddle)로 가면 목록에있는 팀을 새로운 순서로 드래그 앤 드롭 할 수 있습니다. 또한 각 팀이 시즌 중에 얻게 될 점수의 값을 입력 할 수도 있습니다. jQuery는 정렬 순서를 읽은 후에 정렬 순서를 읽고 각 팀의 입력 값을 얻으려고합니다.

바이올린의 경고 (내가 테스트 목적으로 만든 것임)는 첫 번째 위치에 넣은 팀과 그들이 얻으려는 지점의 양을 보여 주어야합니다. 그러나 경고는 발포하지 않습니다. jLint는 코드가 유효하다고 말합니다. 나는 실제로 올바른 값을 얻고 있는지 확인하기 위해 경고를 사용하고 있습니다. 경고가 작동하지 않는 이유를 설명해 주시겠습니까? jQuery를

$("#sortlist").sortable({ 
    stop: function(event, ui) { 
     result = $("#sortlist").sortable("toArray"); 
     var attributes; 
     attributes = { 
      first: { team: result[0].id, value: result[0].children()[0].val() }, 
     second : { team: result[1].id, value: result[1].children()[0].val() }, 
     third: { team: result[2].id, value: result[2].children()[0].val() }, 
     fourth: { team: result[3].id, value: result[3].children()[0].val() }, 
     fifth: { team: result[4].id, value: result[4].children()[0].val() }, 
     sixth: { team: result[5].id, value: result[5].children()[0].val() }, 
     seventh: { team: result[6].id, value: result[6].children()[0].val() } 
     }; 

     alert(attributes.first.team + attributes.first.value); 
    } 
}); 
+1

브라우저의 개발자 콘솔에서 오류 확인 –

+0

경고문 앞에 구문 오류 또는 null 값 오류가 있어야합니다. – madhairsilence

+0

@Ohgodwhy 왜 그런가요? 분명히 '가치'가 정의 된 것을 알 수 있습니다. –

답변

1

$("#sortlist").sortable("toArray")

<form<form id="new_entry"> 

<ul id="sortlist"> 

     <li id="Vancouver">Canucks<input type="text" name="name" id="vanpoints"></li> 
     <li id="Toronto">Toronto<input type="text" name="name" id="torontopoints"></li> 
     <li id="Montreal">Montreal<input type="text" name="name" id="montrealpoints"></li> 
     <li id="Ottawa">Ottawa<input type="text" name="name" id="ottawapoints"></li> 
     <li id="Calgary">Calgary<input type="text" name="name" id="calgarypoints"></li> 
     <li id="Edmonton">Edmonton<input type="text" name="name" id="edmontonpoints"></li> 
     <li id="Winnipeg">Winnipeg<input type="text" name="name" id="winnipegpoints"></li> 
</ul> 
<input type="submit" value="Add"> 
</form> 

문자열의 배열을 정렬 항목의 식별자의 배열을 반환한다.

문자열에 id 속성과 children 메서드가 없습니다.

+0

바이올린 오류 'TypeError : result [0] .children이 함수가 아닙니다. 먼저 : {team : result [0] .id, value : result [0] .children() [0] .val()}, "나는 이드가있다라고 생각하게한다"id "그러나 어떤"children도 없다 " –

+0

대답에 감사드립니다. 나는이 질문에 대한 대답에서 그 코드/아이디어를 얻었다. http://stackoverflow.com/questions/12443908/jquery-how-do-i-access-this-input-value 시간이 있다면, 나는 목록 항목의 ID와 함께 입력 값을 가져 오는 적절한 방법을 설명 할 수 있으면 고맙게 생각합니다. – BrainLikeADullPencil

관련 문제