1

我有一个基于一些 JSON 数据构建多个小部件的表单。该表单的一部分是选择下拉菜单,并且默认情况下某些项目具有不同的选项。

IE:

object 1 {
    tag: "products"
}

ng-repeat 小部件中的选择下拉菜单

<select class="btn-success form-control">
    <option value="companies">companies</option>
    <option value="news">news</option>
    <option value="people">people</option>
    <option value="products">products</option>
</select>

^ 如果这是object 1,我需要 products 选项来获得selected属性。


到目前为止我已经尝试过,但没有奏效,但你可以看到我的想法:

HTML

ng-repeat="stuff in stuffs"...

<select class="btn-success form-control">
    <option value="companies">companies</option>
    <option ng-if="widget.selectedTag(stuff.tag)" value="news">news</option>
    <option value="people">people</option>
    <option value="products">products</option>
</select>

控制器

this.selectedTag= function(s) {
    console.log(s);

    if (s = 'news'){
        return 'selected';
    }
}

你会怎么做?

4

1 回答 1

1

Found answer here: Initializing select with AngularJS and ng-repeat

<option ng-selected="{{operator.value == filterCondition.operator}}"
        ng-repeat="operator in operators"
        value="{{operator.value}}">

So in my case:

<option value="products"
        ng-selected="{{stuff.tag == 'products'}}">products</option>
于 2015-03-17T21:00:23.420 回答