在回台给html下拉框赋值,添加后台list给前台select标签赋值简单实现

$.ajax({

url : "user!findUserList.action",

type : "post",

success: function(data){

var jsonObj=eval("("+data+")");

$.each(jsonObj, function (i, item) {

jQuery("#userList").append(""+ item.userRealName+"");

});

},

error: function(text) {}

});

public void findUserList() throws IOException {

List roleuserList = userService.findUserList();

String json = JSONArray.fromObject(roleuserList).toString();

writeHtml(json);;

}

protected void writeHtml(String strData) {

try {

response.setContentType("text/html; charset=UTF-8");

PrintWriter pw = response.getWriter();

pw.write(strData);

pw.flush();

pw.close();

} catch (IOException e) {

log.error("writeHtml()", e);

}

}

HTML 中使用 `<m-select-box>` 标签通常是在使用 Angular Material 时遇到的组件。为了给这个下拉框赋值以及设置初始值,我们需要在 TypeScript 文件中定义一个数组来存储下拉选项,并且定义一个模型变量来绑定到 `ngModel`。下面是如何在 TypeScript 中给 `<m-select-box>` 赋值及设置初始值的示例代码: 首先,在你的组件的 TypeScript 文件中定义数据源和模型: ```typescript import { Component } from '@angular/core'; @Component({ selector: 'app-your-component', templateUrl: './your-component.component.html', styleUrls: ['./your-component.component.css'] }) export class YourComponent { listData: Array<{ name: string, value: string }> = [ { name: '选项1', value: '1' }, { name: '选项2', value: '2' }, { name: '选项3', value: '3' }, // 添加更多选项... ]; selectedValue: string; // 这将用于绑定到 `ngModel` constructor() { // 初始化时设置选中值 this.selectedValue = this.listData[0].value; } } ``` 接着,在你的 HTML 文件中,使用 `<m-select-box>` 组件,并将 `listData` 和 `selectedValue` 作为属性传递给它: ```html <m-select-box [listData]="listData" [(ngModel)]="selectedValue"></m-select-box> ``` 确保你的模块中已经导入了 `FormsModule` 和 `MatSelectModule`,因为 `ngModel` 是由 `FormsModule` 提供的,而 `<m-select-box>` 可能是 `MatSelectModule` 中的一部分,具体取决于你的项目设置和使用的版本。 ```typescript import { FormsModule, NgModule } from '@angular/core'; import { MatSelectModule } from '@angular/material/select'; // 其他必要的导入... @NgModule({ imports: [ FormsModule, MatSelectModule, // 其他模块... ], // 其他配置... }) export class YourModule { } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值