ng-selected的AngularJs下拉菜单

时间:2018-07-10 08:04:08

标签: javascript angularjs drop-down-menu ng-options

我有一系列用户属性

$scope.userAttributes = [{
    id: 112,
    order: "first"
}, {
    id: 232,
    order: "second"
}, {
    id: 353,
    order: "third"
}, {
    id: 485,
    order: "fourth"
}];

并且我想将此代码段的订单属性用作下拉选项

<select ng-model= "users.number " class="form-control" ng-options="t.order for t in userAttributes"> 
   <option ng-selected="{{t.id== users.number}}">{{t.order}}</option> 
</select>

我也有很多用户

$scope.users = [{
    number: 112,
    age: "eigth",
    name: "alice"
}, {
    number: 232,
    age: "ten",
    name: "jack"
}, {
    number: 353,
    age: "twelve",
    name: "kevin"
}];

我将获得一个表格,该表格将使用下拉列表更改用户顺序,但我希望看到可以根据用户数量预先选择order属性。 例如,当我选择“凯文”时,在下拉列表中应选择“第三”(就像我用ng-selected一样),当我将“第三”更改为“第一”时,应改变开文数如232。

1 个答案:

答案 0 :(得分:0)

pipeline = Pipeline([
# Extract the subject & body
('subjectbody', SubjectBodyExtractor()),

# Use FeatureUnion to combine the features from subject and body
('union', FeatureUnion(
    transformer_list=[

        # Pipeline for pulling features from the post's subject line
        ('subject', Pipeline([
            ('selector', ItemSelector(key='subject')),
            ('tfidf', TfidfVectorizer(min_df=50)),
        ])),

        # Pipeline for standard bag-of-words model for body
        ('body_bow', Pipeline([
            ('selector', ItemSelector(key='body')),
            ('tfidf', TfidfVectorizer()),
            ('best', TruncatedSVD(n_components=50)),
        ])),

        # Pipeline for pulling ad hoc features from post's body
        ('body_stats', Pipeline([
            ('selector', ItemSelector(key='body')),
            ('stats', TextStats()),  # returns a list of dicts
            ('vect', DictVectorizer()),  # list of dicts -> feature matrix
        ])),

    ],

    # weight components in FeatureUnion
    transformer_weights={
        'subject': 0.8,
        'body_bow': 0.5,
        'body_stats': 1.0,
    },
)),
])
X_transformed = pipeline.fit_transform(X)
print(X_transformed.shape)
angular.module('app', []).controller('ctrl', function($scope) {
  $scope.userAttributes = [
    { id: 112, order: "first" }, 
    { id: 232, order: "second" },
    { id: 353, order: "third" }, 
    { id: 485, order: "fourth" }
  ];
  $scope.orderChanged = () => $scope.user.number = $scope.order.id;
  
  $scope.users = [
    { number: 112, age: "eigth", name: "alice" },
    { number: 232, age: "ten", name: "jack" },
    { number: 353, age: "twelve", name: "kevin" }
  ];
  $scope.user = $scope.users[0];
  $scope.userChanged = () => 
    $scope.order = $scope.userAttributes.find(x => x.id == $scope.user.number);
  $scope.userChanged();
})