Specific ideas :
e.detail.value Will get all the information in the form input Value of , So we get each one input Value of
Again data Assign values
example :
<form bindsubmit="submit"> <view wx:for="{{model}}" wx:key="{{index}}"> <input
name="name{{index}}" placeholder="name"></input> <input name="sex{{index}}"
placeholder="sex"></input> </view> <button form-type="submit"> Submit </button> </form
>
js:
Page({ data: { model:[ {id:0,name:null,sex:null}, {id:1,name:null,sex:null} ] }
, submit:function(e){ let model = this.data.model; let name = e.detail.value;
// Get form All in input Value of console.log(name); var i=0,j=1,k=0; for(i=0,j=0;i<model.
length;i++,j++){ var n = "name"+i; var s = "sex"+i; console.log(name[n]);
console.log(name[s]); model[i].name = name[n]; model[i].sex = name[s]; } this.
setData({ model:model }); } })
console.log(name):
Got every one input Of name And its value , Note that the array order is based on the name Of ASCII To sort , So it is not feasible to traverse the assignment directly . Adoption key look for value The way
submit:function(e){ let model = this.data.model; let name = e.detail.value;
console.log(name); var i=0,j=1,k=0; for(i=0,j=0;i<model.length;i++,j++){ var n =
"name"+i; // input name var s = "sex"+i; // input name console.log(name[n]); console.
log(name[s]); // name[sex0] name[sex1] model[i].name = name[n]; model[i].sex =
name[s]; // model[0].sex = name[sex0] // model[1].sex = name[sex1] } this.
setData({ model:model }); },
Technology
Daily Recommendation