是否有任何类(如goog.ui.dialog
)让我显示一个对话框,其内容可以通过 ajax 从其他文件中获取?
good.net.XHR
和goog.ui.Popup
等其他基础类来实现吗?答案 0 :(得分:2)
您可以扩展goog.ui.dialog并获取内容。
一个可以帮助你的简单例子:
my.ui.Dialog = function(opt_iframe) {
goog.ui.Dialog.call(this, null, opt_iframe);
this.xhr_ = new goog.net.XhrIo();
this.xhr_.addEventListener(goog.net.EventType.COMPLETE,
this.onComplete_, false, this);
goog.events.listen(this, goog.ui.Dialog.EventType.SELECT,
this.dispatch_, false, this);
};
my.ui.Dialog.prototype.buildWindow_ = function (responseJson) {
this.setTitle(responseJson.title);
this.setContent(responseJson.content);
this.setButtonSet(eval(responseJson.buttons));
};
my.ui.Dialog.EventType = {
'COMPLETE': 'complete'
};
my.ui.Dialog.prototype.onComplete_ = function (event) {
var json = this.xhr_.getResponseJson ()
this.buildWindow_ (json);
this.reposition ();
};
my.ui.Dialog.prototype.send = function (uri, method, post_data) {
this.xhr_.send(uri, method, post_data, null, {'X-DIALOG':'AJAX'});
};
goog.inherits (my.ui.Dialog, goog.ui.Dialog);
在json中使用响应来构建像这样的ui.Dialog:
{"buttons": "goog.ui.Dialog.Buttons.OK_CANCEL",
"content": "<html><body><h1>Hello</h1></body></html>",
"title": "Hello World"}
此示例无法直接使用:/