PHPCMS V9 relation 后台添加文章 选择“相关文章” 可调用其它模型文章 b并可设置多个 的解决办法
- 修改系统默认的relation字段表单代码如下:
<input type='hidden' name='info[你的字段名]' id='你的字段名' value='{FIELD_VALUE}' style='50' >
<ul class="list-dot" id="你的字段名_text"></ul>
<div>
<input type='button' value="添加相关" onclick="omnipotent('selectid','?m=content&c=content&a=public_relationlist&modelid=目标模型ID&modelname=你的字段名','添加相关文章',1)" class="button" style="width:66px;">
<span class="edit_content">
<input type='button' value="显示已有" onclick="show_myrelation(当前模型ID,目标模型ID,{ID},'你的字段名')" class="button" style="width:66px;">
</span>
</div>
- 打开网站根目录文件statics\js\content_addtop.js
修改remove_relation方法为
function remove_relation(sid, id, modelname) {
var relation_ids = $('#' + modelname).val();
if (relation_ids != '') {
$('#' + sid).remove();
var r_arr = relation_ids.split('|');
var newrelation_ids = '';
$.each(r_arr, function(i, n) {
if (n != id) {
if (i == 0) {
newrelation_ids = n;
} else {
newrelation_ids = newrelation_ids + '|' + n;
}
}
});
$('#' + modelname).val(newrelation_ids);
}
}
修改show_relation函数为:
function show_relation(modelid, id, fieldname) {
$.getJSON("?m=content&c=content&a=public_getjson_ids&modelid=" + modelid + "&id=" + id, function(json) {
var newrelation_ids = '';
if (json == null) {
alert('没有添加相关文章');
return false;
}
$.each(json, function(i, n) {
newrelation_ids += "<li id='" + n.sid + "'>·<span>" + n.title + "</span><a href='javascript:;' class='close' οnclick=\"remove_relation('" + n.sid + "'," + n.id + ",'" + fieldname + "')\"></a></li>";
});
$('#relation_text').html(newrelation_ids