Nis*_*sin 1 javascript twitter-bootstrap angularjs angular-ui angular-ui-bootstrap
我有一个表单中的三个 angular-ui-bootstrap typehead
<form>
<div class="form-group">
<label for="fieldname" class="col-md-3 control-label">Name</label>
<div class="col-md-6">
<input type="text" ng-model="newItem.customSelected" typeahead="name as name.name for name in members | filter:{name:$viewValue}" class="form-control" />
</div>
</div>
<div class="form-group">
<label for="fieldhname" class="col-md-3 control-label">House name</label>
<div class="col-md-6">
<input type="text" ng-model="newItem.customSelected1" typeahead="house_name as house_name.house_name for house_name in family | filter:{house_name:$viewValue}" class="form-control" />
</div>
</div>
<div class="form-group">
<label for="" class="col-md-3 control-label"><?php echo $this->lang->line('label_family_id'); ?></label>
<div class="col-md-6">
<input type="text" ng-model="newItem.customSelected2" typeahead="fm as fm.family_reg_no for fm in family | filter:{family_reg_no:$viewValue}" class="form-control" />
</div>
</div>
<div class="col-md-3"></div>
<input type="button" class="finish btn-success btn" ng-click="search(newItem)" value="Search"/>
</form>
Run Code Online (Sandbox Code Playgroud)
搜索按钮调用函数,
$scope.search = function(item) {
item['id']=item.customSelected.id;
item['family_id']=item.customSelected1.id;
item['family_id']=item.customSelected2.id;
delete data.customSelected;
FamilyMemSearch.get(item, function (response) { // success
$scope.tableData = response.data; // store result to variable
}, function (error) { // ajax loading error
Data.errorMsg(); // display error notification
});
};
Run Code Online (Sandbox Code Playgroud)
但它显示错误 customSelected1,customSelected2 未定义。
ngModel只有在第一次更改值后才会自动创建属性。如果您不初始化item.customSelected1,item.customSelected2并在页面加载后立即单击搜索,则值将为undefined。
尝试初始化您的item.customSelected1和item.customSelected2
app.controller("yourController",function($scope){
$scope.newItem= {};
$scope.newItem.customSelected1 = {};
$scope.newItem.customSelected2 = {};
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6491 次 |
| 最近记录: |