PHPCMS V9 relation 后台添加文章 选择“相关文章” 可调用其它模型文章 b并可设置多个 的解决办法

PHPCMS V9 relation 后台添加文章 选择“相关文章” 可调用其它模型文章 b并可设置多个 的解决办法

  1. 修改系统默认的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>
  1. 打开网站根目录文件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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值