0
이상한 문제가 있습니다. 나는 그것이 변수의 범위와 관련이 있다고 확신하지만, 왜 그럴 수없는 것인지 알 수 없다. 이것은 다음과 같은 코드를 구글 크롬 31.0.1650.57 및 Firefox 24.0에서 수행되고있다 : 먼저 template.js
다음 전화를 함수에 보낼 때 객체의 유형이 정의되지 않았습니다.
$("select[name=class]").change(function() {
var subclassSQL = new Array();
subclassSQL[0] = "`class`, `type`, `subclass`";
subclassSQL[1] = "subclass";
subclassSQL[2] = "class";
subclassSQL[3] = $("select[name=class] option:selected").html();
splitArr = new Array();
splitArr[0] = split;
splitArr[1] = "type";
call(subclassSQL, "subClass", "div.subClass", (function(){split(); Handlebars.registerHelper("top", function(object) {return new Handlebars.SafeString("<span>Choose your " + object[0].type + ":</span>\n<select name=\"subClass\">");});Handlebars.registerHelper("bottom", function() {return new Handlebars.SafeString("</select>");});}), splitArr, false);
});
변경되는 드롭 다운에 의해 트리거됩니다 (다음 섹션
template.js
의 라인 28에서 시작) 호출되는시 콘솔에서이 옵션을 선택하면 ajaxCalls.js의 기능
function call(SQLarray, source, container, helper, function_, run) {
$.ajax({
url: "includes/ajaxHandler.php",
type: 'post',
dataType: 'json',
data: {info: SQLarray},
success: function(json) {
var template = Handlebars.templates[source],
tempData = {base: json}
console.log(tempData.base);
if (helper) {helper();}
if (function_) {
$(container).html(template(function_[0](function_.slice(1), tempData)));
} else {
$(container).html(template(tempData)); }
if (run) {update(jQuery);}
}
});
};
function split(field, tempData) {
console.log(tempData.base);
return tempData;
};
을 트리거, 첫 번째
console.log(tempData.base);
는 예상대로 JSON 개체를 반환합니다. 하지만 두 번째 반환
Uncaught TypeError: Cannot read property 'base' of undefined ajaxCalls.js:22
split ajaxCalls.js:22
(anonymous function) template.js:37
$.ajax.success ajaxCalls.js:11
c jquery.js:3048
p.fireWith jquery.js:3160
k jquery.js:8235
r jquery.js:8778
function_
에 대한 호출의 구문은 다음과 같습니다 왜이 정의되지 않은를 반환
split("type", tempData);
?