【发布时间】:2016-01-05 04:58:15
【问题描述】:
我正在使用 Meteor + Angular 处理网页,我希望用户能够搜索条件。通过搜索按钮提交他们的过滤条件后,我还希望用户查看他们以前的条件堆栈,以便他们可以编辑它。例如:
最初,用户将拥有:
[Enter Field 1] [Search Button]
输入并点击搜索按钮后用户应该看到:
[<"some criteria">] [Search Button]
[Enter Field 1] [Search Button]
在连续输入后,用户应该看到:
[<"some criteria 1">] [Search Button]
[<"some criteria 2">] [Search Button]
.
.
.
[<"some criteria n">] [Search Button]
[Enter Field 1] [Search Button]
我的问题是我希望用户从特定条件中进行选择,而不是在字段区域中输入文本,但是当从文本切换到选择元素时,我遇到了一些角度问题。
每次用户输入条件时,他们都会在历史堆栈中看到选择下拉列表,但它显示为空白,好像没有选择任何内容(尽管 webapp 的行为就像选择的值设置为用户在提交之前选择的值)。
例如,我得到了这个而不是上面想要的
[ Blank ] [Search Button]
[ Blank ] [Search Button]
.
.
.
[ Blank ] [Search Button]
下拉菜单有效,更新这些过去的选择似乎也有效,所以我怀疑 Angular 在自动填充新的选择区域时只是没有将默认值设置为过去的标准。
下面是我用选择行动态填充 div 的代码:
<div id="history" ng-repeat="past in prevSearches">
<select ng-model="past.field" ng-change="myCallback()"
ng-value="past.field" ng-options="option.title for option in colKeys">
</select>
</div>
<select class="form-control" ng-model="colKey" ng-change="myCallback()">
<option value="">--Field--</option>
<option ng-repeat="option in colKeys" ng-value="option.value" ng-bind="option.title"></option>
</select>
<button ng-click="addToPrevSearches()">go</button>
还有 javascript:
$scope.addToPrevSearches: function() {
$scope.prevSearches.push({field:$scope.colKey});
}
有人会认为,因为 ng-model 和 ng-value 被分配了 past.field,所以 past.field 文本将显示为选中而不是空白(特别是因为 Web 应用程序的行为就像它们被正确选中一样),但这不是案例。
我已经在这里尝试了以下帖子,但似乎没有任何效果:
Can't set selected value of ng-options
Angularjs how to set the default value for select
How to select dynamically generated elements from inside an AngularJS directive?
【问题讨论】:
标签: javascript jquery html angularjs meteor