Javascript 将ng选项选定值与对象属性绑定
我正在尝试用选定值绑定对象的属性。我有以下目标Javascript 将ng选项选定值与对象属性绑定,javascript,angularjs,Javascript,Angularjs,我正在尝试用选定值绑定对象的属性。我有以下目标 $scope.data = { sectionQs: $scope.questions, selectedQuestion: '' } 我想根据函数返回的值设置所选值,该值将是下拉部分QS值之一。像 $scope.data.selectedQuestion = returnedValue; 此处returnedValue是一个对象,要绑定的值的结构为returnedValue.data.string。在UI中尝试这
$scope.data = {
sectionQs: $scope.questions,
selectedQuestion: ''
}
我想根据函数返回的值设置所选值,该值将是下拉部分QS值之一。像
$scope.data.selectedQuestion = returnedValue;
此处returnedValue是一个对象,要绑定的值的结构为returnedValue.data.string。在UI中尝试这样绑定
<select ng-model="data.selectedQuestion" ng-options="question.data.string for question in data.sectionQs"></select>
此处,即使设置了选定值,该值仍为空。selectedQuestion属性在调试器中查看时会填充,但它不会显示在UI中。它看起来像是由
ng options
创建的选项将值设置为问题的对象,并且似乎在$scope.data中。selectedQuestion
您没有传递对象。你能告诉我你在$scope.data.sectionQs和$scope.data.selectedQuestion中得到了什么吗?在sectionQs中,我有一个问题对象数组。在selectedQuestion中,我有一个数组对象。一个数组对象的结构是object.data.string。您可以为此创建一些fiddle或plunker吗?看起来选项是由ng options
创建的,将值设置为问题对象,并且似乎在$scope.data.selectedQuestion
中,您没有传递对象。你能告诉我你在$scope.data.sectionQs和$scope.data.selectedQuestion中得到了什么吗?在sectionQs中,我有一个问题对象数组。在selectedQuestion中,我有一个数组对象。其中一个数组对象的结构是object.data.string。您可以为此创建一些fiddle或plunker吗