var ResListWidget = new Class({
Implements : [Options, UrlData, Cyres.ResDataMap],
options : 
{
title : 'res-list',
baseParams : {},
url : "",
template : "",
rows : 15,
renderMode : 'insert',
autoRender : false
},
container : null,
el : null,
tpl : null,
ui : null,
initialize : function(el, options)
{
this.container = $(el);
this.setOptions(options);
if(this.options.autoRender) this.render();
},
getTpl : function()
{
if(!this.tpl) this.tpl = new  Mel.XTemplate(this.options.template);
return this.tpl;
},
getElement : function()
{
return this.el;
},
getUi : function()
{
return this.ui;
},
renderLoading : function()
{
var data = {'title' : this.options.title, 'class' : 'loading', 'data' : []};
data['baseParams'] = this.options.baseParams;

var code = this.getTpl().apply(data);
this.updateToView(code);
},
updateToView : function(code)
{
if(this.options.renderMode == 'insert')
{
if(this.ui)
{
this.ui.empty();
this.ui.set('html', code);
}
else
{
this.ui = new Element('div', {'html' : code});
this.container.adopt(this.ui);
}
}
else
{
this.container.set('html', code);
this.ui = this.container;
}
},
render : function()
{
this.renderLoading();
var cb = function(data)
{
//wxq
if(data == null){
data = {'title' : this.options.title, 'class' : 'loading', 'data' : []};
}
data['baseParams'] = this.options.baseParams;
if(this.options.rows > 0) 
data['data'] = data['data'].slice(0, this.options.rows);

data['title'] = this.options.title;
if(this.dataMap !== null) data['data'] = data["data"].map(this.dataMap, this); 
/**
data['data'] = data["data"].map();
*/
var code = this.getTpl().apply(data);
this.updateToView(code);
if(this.afterRender) this.afterRender(this);
}.bind(this);
this.requestData({}, cb);
}
});Cyres.ResList = 
{
apply : function(sel, opts)
{
opts = $pick(opts, {});
opts = $merge({
title : '',
baseParams : {},
rows : 15,
renderMode : 'insert',
autoRender : true
}, opts);
var retval = $$(sel).map(function(o)
{
var tpl = o.getElement('textarea').value;
var url = o.getElement('input[type=hidden]').value;
var rlw = new ResListWidget(o, $merge(opts, {url : url, template : tpl}));
if(opts.afterRender) rlw.afterRender = opts.afterRender;
return rlw;
});
return retval;
}
};

解决方案 »

  1.   

    你使用的这个API没有各个参数的注释吗?
      

  2.   

    这个是别人写的一个自定义的函数,前台的<script>调用了这个函数
      

  3.   


    <script type="text/javascript">
    var i = -1;
    $H(CONFIG.bis).each(function(o)
    {
    var ft = new ResListWidget($('favorate-res-panel'),
    {title : o.display_name, template : $('res-list-tpl').get('value'), rows : 10,
    url : CONFIG.resListUrl + "/",baseParams : {'format' : 'json',
    'dest' : 'textbook-' + o.id
    }, 'renderMode' : 'insert'});
    ft.afterRender = function()
    {
    Cyres.Icon.apply(ft.ui.getElements('ui.data a'));
    $$(ft.ui.getElements('li:even')).addClass('odd');
    };
    ft.render();
    if(++i % 2 == 1) $('favorate-res-panel').adopt(new Element('br', {'clear' : 'all'}));
    });
    </script>