How can I add ajax data into a checkbox?
How can I add ajax data into a checkbox?
Hi Alan,
here's my javascript:
editor1.on('preOpen', function (e) {
e.preventDefault();
$.ajax({
url: '/api/boss/vipCredit',
data: {id:table.row( '.selected' ).data().sc_channel_credits.channelId},
success:function(data) {
console.log(data);
editor1.add({
label: "会员卡信息:",
name: "sc_org_vips[].name",
type: "checkbox",
options:data
});
}
});
});
and here's the ajax data format:
[{"id":1,"name":"vip1"}]
When I tried to launch it , there's some error occured.
Would you please tell me how to insert the checkbox value by the option method or there's a correct method to add it?
One more question, due to the ajax delay, which event should I insert the ajax to add the checkbox before the editor opened?
This discussion has been closed.
Answers
What I would recommend is that you use the
update()
method of thecheckbox
field type. Have thesc_org_vips[].name
field in the standardfields
array, and then update the options using your Ajax call with something like:Regards,
Allan