我想创建一个动态表单,我想从JSON数据创建Form。我能够创建一个表单但我想访问该动态创建的表单并获取提交按钮上的模型(输入字段)的值。 我为此创建了一个小提琴(https://jsfiddle.net/anujsphinx/dpzgeyt8/2/)。想要获得每个领域的ng-model值。 我在HTML中做错了
func tableView(_ tableView: UITableView, didSelectRowAtIndexPath indexPath: IndexPath) {
let tableCell: SearchTableViewCell = tableView.dequeueReusableCell(withIdentifier: "searchcell") as! SearchTableViewCell
if(self.searchstatus == "people")
{
if(useridarray.object(at: (indexPath as NSIndexPath).row) as! NSString != "null" )
{
self.searchdelegate.otheruserid=useridarray.object(at: (indexPath as NSIndexPath).row) as! NSString;
let ProfilePageViewController = self.storyboard?.instantiateViewController(withIdentifier: "otherprofile")
self.present(ProfilePageViewController!, animated: false, completion: nil)
}
}
else
{
if(useridarray.object(at: (indexPath as NSIndexPath).row) as! NSString != "null")
{
let hashtag1=search.text!.replacingOccurrences(of: "#", with: "")
self.searchdelegate.hashtag="\(hashtag1)" as NSString!
self.searchdelegate.hashtag=searchdelegate.hashtag.trimmingCharacters(in: CharacterSet.whitespaces) as NSString!
self.searchdelegate.hashtag=searchdelegate.hashtag.replacingPercentEscapes(using: String.Encoding.utf8.rawValue) as NSString!
let hashtag = self.storyboard?.instantiateViewController(withIdentifier: "hashtag")
self.present(hashtag!, animated: false, completion: nil)
}
}
}
答案 0 :(得分:2)
这是获取所有表单元素值的方法。 添加新表单元素并在表单中添加输入字段。
<form name="newForm">
... //input elements
</form>
添加循环以获取表单中所有元素的值
$scope.checkResult = function(){
var newForm = document.newForm;
for(i=0;i<newForm.elements.length;i++){
console.log(newForm.elements[i].value);
}
}
希望有所帮助