jquery或者js怎么操作实体类中的值

JavaScript014

jquery或者js怎么操作实体类中的值,第1张

现在js主流使用jquery框架

例如 <input id="name" type="text" value="3" />

使用jquery框架可以按以下方式取值

var name = $("#name").val()

设值

$("#name").val("456")

1、由后台action

传给前台是需要将map

转成json格式

复制代码

代码如下:

Map<String,

List>

resultMap;

JSONObject

json

=

JSONObject.fromObject(resultMap)

message

=

json.toString()

List中存放多个student对象

2、前台js

中先将结果json串转成对象

复制代码

代码如下:

var

obj

=

eval("("+data+")")

3、遍历取list

中的对象

复制代码

代码如下:

for(var

key

in

obj){

//第一层循环取到各个list

var

List

=

obj[key]

for(var

student

in

List){

//第二层循环取list中的对象

alert(List[student

].id)

alert(List[student

].name)

}

}

business.ResultType = Ext.extend(Ext.form.ComboBox, {

editable: false,

typeAhead: true,

mode: 'local',

readonly: true,

triggerAction: 'all',

selectOnFocus: true,

plugins: new Ext.ux.plugin.TriggerfieldTooltip(),

tooltip: {

title: '结果类型',

text: '请选择结果类型'

},

valueField: 'ID',

displayField: 'NAME',

initComponent: function() {

this.store = new Ext.data.SimpleStore({

fields: ['ID', 'NAME'],

data: [

['10', '1],

['20', '2'],

['30', '源'],

['40', '访'],

['50', '向'],

['60', '已']

]

})

business.ResultType.superclass.initComponent.call(this)

}

})