안녕하세요 나는 다음과 같은 코드가 있습니다녹아웃와 결합 리드에 "xxx는 함수 아니다"
<ul data-bind="with : weather()" >
<li>Aktuelles Wetter (15:48)
<ul>
<li>
<span style="float:right;" data-bind="text : weather()" onclick="alert(weatherViewModel.weather().wind.speed);"> km/h </span>
내가 항상 오류가 나타납니다 Typerror : 날씨가 함수되지 않습니다. 문제는 내가 data-bind="with : weather"
을 나가면 그 문제가 발생하지 않는다는 것입니다. onclick
속성에 표시된대로 속성에 액세스해야하기 때문에 with-binding이 필요합니다. 아무도 도와 줄 수 있습니까?
업데이트 : 뷰 모델의
var weatherViewModel = {
weather : ko.observable(null),
forecast: ko.observable(null)
}
중요한 부분. 다음과 같이 관찰 검도-UI를 사용하여 Ajax 요청을 통해 설정됩니다
change: function(e) {
console.debug("weatherDataSource.change");
console.log("action: " + e.action);
if (e.action == "sync") {
console.log("Retrieve weather data...");
this.read();
} else {
var data = this.data();
console.log(data[0]);
weatherViewModel.weather(data[0]);
}
}
을하지만 난이 온 클릭 이벤트와 데이터를 액세서 수 있기 때문에 이것은 작동합니다. 이유는 바인딩을 필요로하는 이유는 ajax 요청이 dom 요소 다음에 수행되기 때문에 weather()에 액세스 할 수 없었기 때문입니다. wind.speed, weather()는 처음에 null이기 때문에.
viewmodel을 게시 할 수 있습니까? – Damien
물론 업데이트되었습니다. 감사. – amaik