browserLink:37未捕获错误:语法错误,无法识别的表达式:输入#{role}(...)
// template
<div ng-repeat="role in roles">
<input type="checkbox" id="{{role}}" value="{{role}}" ng-model="role" ng -checked="getCheckedTrue[{{role}}]" />
{{role}}
</div>
// JS
$scope.roles = [
'Dentist',
'HeartSurgeon',
'Cance'
];
$scope.getCheckedTrue = function (data) {
console.log(data);
$http({
method: 'GET',
url: '/Doctor/getType?searchString=' + $scope.role,
}).then(function successCallback(responce) {
$scope.Doctors = responce.data;
}, function errorCallback(response) {
alert("Error : " + response.data.ExceptionMessage);
});
};`
//控制器
public JsonResult getType(string searchString)
{
var Doctor = db.DocMaster.Where(f =>
f.DocType.StartsWith(searchString)).ToList();
var JsonResult = Json(Doctor, JsonRequestBehavior.AllowGet);
JsonResult.MaxJsonLength = int.MaxValue;
return JsonResult;
}
答案 0 :(得分:1)
//For getting the all records from database. Controller
//c# controller
public JsonResult get(string searchString)
{
var Doctor = db.DocMaster.Where(f =>
f.DocType.StartsWith(searchString)).ToList();
var JsonResult = Json(Doctor, JsonRequestBehavior.AllowGet);
JsonResult.MaxJsonLength = int.MaxValue;
return JsonResult;
}
//视图
<div ng-repeat="(typeKey, typeVal) in roles">
<div ng-repeat="value in typeVal">
<label>
<input type="checkbox"
ng-model="x"
ng-change="setOutput(typeKey, $index, value)">{{value}}
</label>
</div>
</div>
//角控制器
$scope.outputs = {};
$scope.setOutput = function (typeKey, $index, value) {
$scope.Doctors = {};
$http({
method: 'POST',
url: '/Doctor/get?searchString='+value,
}).then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available
console.log(response);
$scope.Doctors = response.data;
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
alert("Error : " + response.data.ExceptionMessage);
});
};
答案 1 :(得分:0)
按名称而不是输入引用输入
答案 2 :(得分:0)
我认为ng-checked =“getCheckedTrue [{{role}}]”实际上应该是ng-checked =“getCheckedTrue [role]”
答案 3 :(得分:0)
getCheckedTrue是函数,您将它用作数组。
所以,而不是getCheckedTrue [{{role}}],它应该是getCheckedTrue({{role}})
此外,角色值为字符串,因此您最好使用getCheckedTrue('{{role}}')