下拉菜单的默认值 [英] Default Value for Dropdown

查看:88
本文介绍了下拉菜单的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎无法轻松找到该问题的答案.

Can't seem to find an answer to this issue easily.

要显示并允许编辑的字段的默认值,最好的地方似乎是在草稿记录中设置widget.value,因此默认日期为widget.value = new Date(),等等.

Default values for fields you want to display and allow editing, the best place seems to be to set the widget.value in a draft record, so default date widget.value = new Date(), etc.

如何引用一个下拉列表,其中该下拉列表是一个相关的表查找,例如,属性列表,其中选项的绑定为@datasources.Property.Items,值的绑定为@datasource.Item.Property.

How do I reference a dropdown where the dropdown is a related table lookup, e.g., a list of Properties where the bindings are @datasources.Property.Items for the options and @datasource.Item.Property for the value.

如果我执行console.log(widget.value);,我会得到object Object,这是我期望的,因为它是object类型的.但是,如何设置(并检索)其值?

If I do console.log(widget.value); I get object Object, which is what I would expect because it is of type object. But how can I set (and retrieve) its value?

帮助表示赞赏.

推荐答案

我在自己的应用程序中针对类似情况进行了测试.请注意,在下拉列表中的值实际填充之前,有一个最小的延迟.由于上述我在上一条评论中所述的原因,我不确定您会选择哪种替代解决方案.我可能建议改为在您的表单模型中将其设置为onBeforeCreate事件,但随后您将失去在表单本身中更改关系的功能,因此可能对您不起作用.

I tested this for a similar situation in my own application. Do note that there is a minimal delay before the value in the dropdown actually populates. I'm not sure what your alternative solution could be due to the reason stated in my last comment above. I might suggest setting this in your form model onBeforeCreate event instead, but then you would loose the ability to change the relation in the form itself so that might not work for you.

Dropdown小部件的onAttach事件:

Dropdown widget onAttach event:

var datasource = app.datasources.Property;
if(!datasource.loaded) {
  datasource.load(function() {
    var index = datasource.items.map(function(i){return i.Status;}).indexOf('Open');
    if(index !== -1) {
      widget.value = datasource.items[index];
    }
  });
} else {
  var index = datasource.items.map(function(i){return i.Status;}).indexOf('Open');
  if(index !== -1) {
    widget.value = datasource.items[index];
  }
}

这篇关于下拉菜单的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆