0

我有一个 w2ui 表单,其中包含一个 w2ui Drop List 选项。选择将根据用户选择显示表单的内容而有所不同。我的问题是:下拉列表的内容可以在渲染后更改吗?

使用标准的 HTML 控件,我会做这样的事情:

$("#mySelect option[value='xyz']").remove();

或者

$("#mySelect").append('<option value="abc">abc</option>');

这些操作可以用 w2ui Drop List 来完成吗?任何示例代码?

4

1 回答 1

1

在 w2ui 1.5 中,您可以使用$jQueryElement.w2field()来访问 w2fild 对象 - 然后对其进行操作。

例子:

var field = $("#my_input").w2field();
field.options.items = ["my", "new", "items"];
// optionally: pre-select first item
field.setIndex(0);
// if you do NOT use "setIndex" you need to call "refresh" yourself!
// field.refresh(); 

注意:setIndex()内部调用refresh()- 如上所述,在这种情况下您不需要自己调用刷新。

如果您想完全清除/清空您的字段,您可以调用field.reset().


编辑:在澄清它是关于一个表单字段之后:

// Note: ``this`` refers to the w2form
// ``field[8]`` refers to a field of type "select"
  this.fields[8].options.items = ["my", "new", "items"];
  this.record = {
    field_select: 'new'
  };
  this.refresh();
于 2017-02-05T08:50:05.790 回答