使用 Appcelerator 将值正确传递给函数
Passing value to a function properly with Appcelerator
太快了,我被难住了。
希望在我的 Appcelerator 应用程序中显示一个弹出窗口,它工作正常,但我似乎无法获取变量并将其传递给我的函数,因为它总是以未定义的形式返回。
此处未发布弹出式代码片段,因为这不是问题所在。
这里可能是一个彻头彻尾的小学生错误,谁能指出我做错了什么?
因此,当用户点击 PosterView(通过 HTTP 请求即时创建)时,我需要将 "ourscreenName" 和 "ourscreenURL" 传递到 showOurscreenBooking 函数中。
var xhr = Ti.Network.createHTTPClient({
onload: function() {
// Ti.API.debug(this.responseText);
json = JSON.parse(this.responseText);
Ti.API.info(json);
for (i = 0; i < json.length; i++) {
posterView = Ti.UI.createImageView({
width: Ti.Platform.displayCaps.platformWidth / 3,
defaultImage: 'images/imgloader.png',
top: 0,
backgroundColor: '#000'
});
getPoster(json[i].tmdb_id, posterView, json[i].ourscreen_film_name);
ourscreenName = json[i].ourscreen_film_name;
ourscreenURL = json[i].ourscreen_url;
scrollView.add(posterView);
posterView.addEventListener('click', function(e) {
// need to open up the booking popup
showOurscreenBooking(e.ourscreenName, e.ourscreenURL);
});
}
},
onerror: function(e) {
Ti.API.debug("STATUS: " + this.status);
Ti.API.debug("TEXT: " + this.responseText);
Ti.API.debug("ERROR: " + e.error);
alert('There was an error retrieving the remote data in event loop. Try again.');
},
timeout: 30000 // add longer timeout for slower connections
});
谢谢!
西蒙
不要认为这是最佳做法(在漫长的一天工作后我真的需要呼吸新鲜空气),但你可以做的是:
getPoster(json[i].tmdb_id, posterView, json[i].ourscreen_film_name);
ourscreenName = json[i].ourscreen_film_name;
ourscreenURL = json[i].ourscreen_url;
// add your properties as custom properties to the view
posterView = Ti.UI.createImageView({
width: Ti.Platform.displayCaps.platformWidth / 3,
defaultImage: 'images/imgloader.png',
top: 0,
backgroundColor: '#000',
ourscreenName: ourscreenName,
ourscreenUrl: ourscreenUrl
});
scrollView.add(posterView);
posterView.addEventListener('click', function(e) {
showOurscreenBooking(e.source.ourscreenName, e.source.ourscreenURL);
});
另见 https://archive.appcelerator.com/question/12111/event-propagation----how-to-use-eventsource-property
太快了,我被难住了。
希望在我的 Appcelerator 应用程序中显示一个弹出窗口,它工作正常,但我似乎无法获取变量并将其传递给我的函数,因为它总是以未定义的形式返回。
此处未发布弹出式代码片段,因为这不是问题所在。
这里可能是一个彻头彻尾的小学生错误,谁能指出我做错了什么?
因此,当用户点击 PosterView(通过 HTTP 请求即时创建)时,我需要将 "ourscreenName" 和 "ourscreenURL" 传递到 showOurscreenBooking 函数中。
var xhr = Ti.Network.createHTTPClient({
onload: function() {
// Ti.API.debug(this.responseText);
json = JSON.parse(this.responseText);
Ti.API.info(json);
for (i = 0; i < json.length; i++) {
posterView = Ti.UI.createImageView({
width: Ti.Platform.displayCaps.platformWidth / 3,
defaultImage: 'images/imgloader.png',
top: 0,
backgroundColor: '#000'
});
getPoster(json[i].tmdb_id, posterView, json[i].ourscreen_film_name);
ourscreenName = json[i].ourscreen_film_name;
ourscreenURL = json[i].ourscreen_url;
scrollView.add(posterView);
posterView.addEventListener('click', function(e) {
// need to open up the booking popup
showOurscreenBooking(e.ourscreenName, e.ourscreenURL);
});
}
},
onerror: function(e) {
Ti.API.debug("STATUS: " + this.status);
Ti.API.debug("TEXT: " + this.responseText);
Ti.API.debug("ERROR: " + e.error);
alert('There was an error retrieving the remote data in event loop. Try again.');
},
timeout: 30000 // add longer timeout for slower connections
});
谢谢!
西蒙
不要认为这是最佳做法(在漫长的一天工作后我真的需要呼吸新鲜空气),但你可以做的是:
getPoster(json[i].tmdb_id, posterView, json[i].ourscreen_film_name);
ourscreenName = json[i].ourscreen_film_name;
ourscreenURL = json[i].ourscreen_url;
// add your properties as custom properties to the view
posterView = Ti.UI.createImageView({
width: Ti.Platform.displayCaps.platformWidth / 3,
defaultImage: 'images/imgloader.png',
top: 0,
backgroundColor: '#000',
ourscreenName: ourscreenName,
ourscreenUrl: ourscreenUrl
});
scrollView.add(posterView);
posterView.addEventListener('click', function(e) {
showOurscreenBooking(e.source.ourscreenName, e.source.ourscreenURL);
});
另见 https://archive.appcelerator.com/question/12111/event-propagation----how-to-use-eventsource-property