EasyUI中Combobox查询默认选中查询结果第一项

1.下面是js文件中直接根据id加载数据的方法。红框是加载第一项的通用方法,加载的是data的值,其中changeArr是一个json数组,注意valueField和textField与json数组的“键”:id和name保持一致。

 

 

2.也可以从数据库加载数值,url写地址,要求后台方法返回的结果是json数组,并且也是以id和name为键的。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
用法举例:从数据表name字段写入VALComboBox的items,id字段写入VALComboBox的values,当从VALComboBox选择一个选项后,就可以从value属性获得相应的ID,或者写value的为某ID,VALComboBox将定位在相应的选项上;unit VALComboBox;interfaceuses SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls, Forms, Menus, Dialogs, StdCtrls;type TValComboBox = class(TComboBox) private FValue: PString; FValues: TStrings; FOnChange: TNotifyEvent; function GetValue: string; function GetButtonValue(Index: Integer): string; procedure SetValue(const Value: string); procedure SetValues(Value: TStrings); protected procedure Change; dynamic; procedure Notification(AComponent: TComponent; Operation: TOperation); override; public constructor Create(AOwner: TComponent); override; destructor Destroy; override; property Value: string read GetValue write SetValue; property ItemIndex; published property Values: TStrings read FValues write SetValues; property OnChange: TNotifyEvent read FOnChange write FOnChange; end;procedure Register;implementationconstructor TValComboBox.Create(AOwner: TComponent);begin inherited Create(AOwner); FValue := NullStr; FValues := TStringList.Create; style := csDropDownList;end;destructor TValComboBox.Destroy;begin DisposeStr (FValue); FValues.Free; inherited Destroy;end;procedure TValComboBox.Notification(AComponent: TComponent; Operation: TOperation);begin inherited Notification(AComponent, Operation);end;function TValComboBox.GetValue : string;begin result:=values[itemindex];end;function TValComboBox.GetButtonValue(Index: Integer): string;begin if (Index < FValues.Count) and (FValues[Index] ‘‘) then Result := FValues[Index] else if (Index < Items.Count) then Result := Items[Index] else Result := ‘‘;end;procedure TValComboBox.SetValue (const Value: string);var I : Integer;begin AssignStr(FValue, Value); if (ItemIndex < 0) or (GetButtonValue(ItemIndex) Value) then begin if (ItemIndex >= 0) then ItemIndex := -1; for I := 0 to Items.Count - 1 do begin if GetButtonValue(I) = Value then begin ItemIndex := I; break; end

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值