如何将struts1与angularjs混合以自动填充字段
How to mix struts1 with angularjs to auto populate a field
我正在用struts1构建一个jsp页面(我不能使用struts2),其中我有一个字段,我正在用表单中的值自动填充,但用户可以自由覆盖该文本字段中的任何内容。我还使用了AngularJS,以便在用户重写struts预先填充的值时,在用户键入(类似谷歌的搜索)时提供选项。
我的问题是struts中的html:text标记无法识别标记ng-model和uib-typeahead。如果我切换到纯html输入标记,那么angular特性就可以工作,但现在我无法用struts预先填充字段。
script.js:
angular.module('plunker', ['ui.bootstrap','ngAnimate']).controller('TypeaheadCtrl', function($scope, $http) {
$scope.selected = undefined;
// Any function returning a promise object can be used to load values asynchronously
$scope.getLocation = function(val) {
return $http.get('http://maps.googleapis.com/maps/api/geocode/json', {
params: {
address: val,
sensor: false
}
}
).then(function(response){
return response.data.results.map(function(item){
return item.formatted_address;
});
});
};
});
mypage.html
<body ng-controller="TypeaheadCtrl">
<div class='container-fluid typeahead-demo' >
<div class="section">
<!-- OPTION 1: angular works and gives suggestions, but the field doesn't get pre-populated by struts-->
<input type="text" name="city" id="city" class="gui-input" ng-model="asyncSelected" uib-typeahead="address for getLocation($viewValue)" placeholder="Type city name">
<html:hidden property="city"/>
<!-- OPTION 2: auto-populates value but it can't compile with ng-model and typegead tags -->
<html:text property="city" styleClass="gui-input" styleId="cityStyle" />
</div>
</div>
有人能告诉我最好的方法或合适的方法是什么吗?如何混合选项1和选项2的功能?
提前谢谢。
我已经通过在加载时使用jquery设置字段的值来解决了这个问题,但如果有人有更好的解决方案或更好的实践,我想知道。
相关文章:
- 如何使用与单个查找字段相关的信息填充字段
- 动态填充字段的Jquery验证
- 使用另一个字段的日期+14天自动填充字段
- Mongoose,按填充字段对查询进行排序
- 使用 Codeigniter 和 jquery 在 Modal Bootstrap 3 中的 DB 中填充字段
- 填充字段后更改不透明度
- 根据下拉选择(Javascript / HTML)动态填充字段
- JavaScript 重置 PHP/AJAX 中的填充字段
- 对填充字段的 MongoDB 查询
- 根据 $_POST 值填充字段
- Javascript 自动完成表单并在预填充字段中附加文本
- Jquery 未完成填充字段
- 在客户端使用 javascript、ajax 或 php 计算填充字段的数量
- 使用地理位置坐标填充字段
- 根据同时在另一个字段中输入的内容自动填充字段
- 如何将struts1与angularjs混合以自动填充字段
- 填充字段,该字段是单个查询中嵌入数组的属性
- Phantom.js填充字段,点击提交,现在只能访问下一页
- 如何在预填充字段时清除iOS占位符JS文本
- 我的response.jsp赢了'无法正确填充字段