js 中用 标签时 空会报错 要先判断一下${question.selectanswer!=null}

本文介绍如何使用EL表达式中的三元运算符来简化页面上对于变量的条件判断逻辑,通过具体的代码示例展示了如何根据变量的不同状态进行不同的处理。
这个问题 以后就不用判断了 用el表达式中的三元运算符解决了



${question.selectanswer==null?"":question.selectanswer};
// if(${question.selectanswer!=null}){
var a = new Array();

// a=${question.selectanswer};
a= ${question.selectanswer==null?"[]":question.selectanswer};
for(var i=0;i<a.length;i++ ){

$("#select").append('<ul><input type="text" value="'+a[i]+'" name="answers" style="width:300px"></ul>');
}
// }


<div class="fm-tmpl-listview-common fm-tmpl-listview-card"> <div class="fm-tmpl-listview-content"> <!-- 题目类型作为标题显示 --> <div class="fm-tmpl-row"> <div class="fm-tmpl-col"> <div class="fm-tmpl-label"> <div class="fm-tmpl-label-text" style="font-weight: bold;"> <!-- 只显示题目类型的数据 --> {{$formatUtils.enum(props.item.questionType,{enumData:[{"disabled":false,"name":"单选题","value":"单选题"},{"disabled":false,"name":"多选题","value":"多选题"},{"disabled":false,"name":"判断题","value":"判断题"}]})}} </div> </div> </div> </div> <!-- 题目题干 --> <div class="fm-tmpl-row"> <div class="fm-tmpl-col"> <div class="fm-tmpl-label"> <div class="fm-tmpl-label-text"> 题目题干:{{props.item.questionvarchar2}} </div> </div> </div> </div> <!-- 根据题目类型动态显示选项 --> <div class="fm-tmpl-row"> <div class="fm-tmpl-col"> <div class="fm-tmpl-label"> <div class="fm-tmpl-label-text"> <!-- 单选题 --> <template v-if="props.item.questionType === '单选题'"> <label> <input type="radio" :name="'option_' + props.item.id" value="A"> 选项A:{{props.item.optionA}} </label><br> <label> <input type="radio" :name="'option_' + props.item.id" value="B"> 选项B:{{props.item.optionB}} </label><br> <label> <input type="radio" :name="'option_' + props.item.id" value="C"> 选项C:{{props.item.optionC}} </label><br> <label> <input type="radio" :name="'option_' + props.item.id" value="D"> 选项D:{{props.item.optionD}} </label> </template> <!-- 多选题 --> <template v-else-if="props.item.questionType === '多选题'"> <label> <input type="checkbox" :name="'option_' + props.item.id" value="A"> 选项A:{{props.item.optionA}} </label><br> <label> <input type="checkbox" :name="'option_' + props.item.id" value="B"> 选项B:{{props.item.optionB}} </label><br> <label> <input type="checkbox" :name="'option_' + props.item.id" value="C"> 选项C:{{props.item.optionC}} </label><br> <label> <input type="checkbox" :name="'option_' + props.item.id" value="D"> 选项D:{{props.item.optionD}} </label> </template> <!-- 判断题 --> <template v-else-if="props.item.questionType === '判断题'"> <label> <input type="radio" :name="'option_' + props.item.id" value="A"> 正确 </label><br> <label> <input type="radio" :name="'option_' + props.item.id" value="B"> 错误 </label> </template> </div> </div> </div> </div> </div> </div> 把选择的选项传过去 持久化 然后再回到次条数据的候再获取 如果首次打开次数据则默认什么都没选中import { BaseDataService, LoadDataService } from '@farris/mobile-command-services'; import { ViewModelContext, HttpClient } from '@farris/mobile-devkit'; import { switchMap } from 'rxjs/operators'; import { map } from 'rxjs/operators'; export class ExpenseMfrmControllerService extends BaseDataService { private httpClient: HttpClient; private loadDataService: LoadDataService; private s: number = 0; // 初始化 s 的值为 0 private res: any[] = []; // 初始化 res 为数组 constructor(viewModelContext: ViewModelContext) { super(viewModelContext); this.httpClient = new HttpClient(); this.loadDataService = this.getService<LoadDataService>(LoadDataService); } /** * 自定义取数 * @remarks * @returns s.returnValue.result[0] */ public myLoadData() { return this.loadDataService.loadForList().pipe( switchMap(response => { this.res = response; // 存储响应数据 const myFilters = [{ Compare: 0, Expresstype: 0, FilterField: "ID", Lbracket: "", Rbracket: "", Relation: 0, Value: this.res[this.s].newData.id }]; // 取数 const filters = this.loadDataService.mergeFilters(myFilters, true); console.log(this.res[this.s].newData.id, '423423234242343242filters'); return this.loadDataService.loadForList(filters); }) ); } /** * 增加 s 的值 */ public incrementS() { if (this.s < this.res.length - 1) { // 确保 s 不超过数组长度减一 this.s++; } const myFilters = [{ Compare: 0, Expresstype: 0, FilterField: "ID", Lbracket: "", Rbracket: "", Relation: 0, Value: this.res[this.s].newData.id }]; const filters = this.loadDataService.mergeFilters(myFilters, true); return this.loadDataService.loadForList(filters); } /** * 减少 s 的值 */ public decrementS() { if (this.s > 0) { // 确保 s 大于 0 this.s--; } const myFilters = [{ Compare: 0, Expresstype: 0, FilterField: "ID", Lbracket: "", Rbracket: "", Relation: 0, Value: this.res[this.s].newData.id }]; const filters = this.loadDataService.mergeFilters(myFilters, true); return this.loadDataService.loadForList(filters); } }
05-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值