如何使用jquery动态设置下拉菜单更改时的summernote值?

问题描述 投票:0回答:1

模型.py

class Other(models.Model):
    desc = models.TextField(default=None)

    create_by = models.ForeignKey(User, on_delete=models.CASCADE)
    create_at = models.DateField(auto_now_add=True)
    update_at = models.DateField(auto_now=True)

表单.py

class OtherForm(forms.ModelForm):
    
    class Meta:
        model = Other
        fields = "__all__"
        exclude = ['create_by','create_at','update_at']

        widgets = {
            'desc':SummernoteWidget(attrs={'summernote': {'width': '100%', 'height': '400px'}}),
        }

index.html

<div class="card-body">
            <label for="">Templates</label>
            <select class="form-control form-control-sm form-select" name="template" id="id_template">
                <option value="">--</option>
                {% for i in data %}
                <option value="{{i.id}}">{{i.name}}</option>
                {% endfor %}
            </select>
            <form method="post" action="">
                {% csrf_token %}
                {{form}}
                <div class="row">
                    <div class="col-6">
                        <button type="submit" class="btn btn-soft-primary">{{btn_type}}</button>
                        <a href="{% url tree_url %}" class="btn btn-soft-gray">Bank</a> 
                    </div>
                </div>
            </form>
        </div>

Js.file

$('#id_template').change(function () {
    var id_template = $("#id_template").val()
      $.ajax({
        type:'GET',
        url:'{% url "templates_find" %}',
        data:{id_template:id_template},
        success:function (data, status) {
        var h_content = data.t_data
        console.log(h_content)
         
        }
      });

当我更改下拉菜单 jQuery ajax 调用并获取正确的模板值但无法在 Summernote 编辑器上设置时 我尝试使用这个 $('.summernote').summernote('code', data.message);但仍然无法正常工作,请指导。 我已经为模板创建了模板主控以保存不同的模板 现在我希望那些想要保存模板的人以其他形式 Summernote 编辑器显示 这是我的模板主图像。 这里还有其他模板表格

jquery django summernote
1个回答
0
投票

根据我检查编辑器的内容,您需要按如下方式操作:

$('.note-editable').text('def');

或家长参考:

$('.note-editor').find('.note-editable').text('def def');
© www.soinside.com 2019 - 2024. All rights reserved.