从DropDown中选择值

从DropDown中选择值

本文介绍了AngularJs:从DropDown中选择值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AngularJS和JQM我创建了一个下拉列表,用于使用AngularJS Controller选择其中的值和数据。它工作正常
但是当我在中添加 data-native-menu =false < select> 然后奇怪的执行
我选择它选择的第一个值。

I am using AngularJS with JQM I create a drop-down for selecting value and data comies in it using AngularJS Controller. It works fineBut when I add data-native-menu="false in <select> then strange executionsI select first value it selected second.

我的HTML部分

<div ng-controller="MyCtrl">
    <select data-native-menu="false" data-role="listview" ng-options="size as size.name for size in sizes " ng-model="item" ng-change="update()"></select>
     {{item.code}} {{item.name}}
</div>

JS Part

myApp.controller('MyCtrl',function($scope){
    $scope.sizes = [ {code: 1, name: 'n1'}, {code: 2, name: 'n2'}];
    $scope.update = function() {
    console.log($scope.item.code, $scope.item.name)
}});

如果我删除 data-native-menu =falsedata-role =listview然后代码工作正常

If I remove data-native-menu="false" data-role="listview" then code works fine

请帮助我

我的示例的演示页面是

Demo Page of My Example is Here

推荐答案

你可以在

You can find working code in

html

<div ng-controller = "fessCntrl" >
 <div query-mobile-tpl>
  <select data-role="listview" data-inset="true" ng-options="size as size.name for size in sizes " ng-model="item" x-ng-change="update(item)"></select>
  <pre> {{item.code | json}} {{item.name | json}}</pre>
  </div>
</div>

控制器

 var fessmodule = angular.module('myModule', []);

fessmodule.controller('fessCntrl', function ($scope) {

    $scope.sizes = [ {code: 1, name: 'n1'}, {code: 2, name: 'n2'}];
    $scope.update = function() {
    console.log($scope.item.code, $scope.item.name)
    };
});


fessmodule.directive('jqueryMobileTpl', function() {
  return {
    link: function(scope, elm, attr) {
      elm.trigger('create');
    }
  };
});

fessmodule.directive('repeatDone', function () {
    return function (scope, element, attrs) {
        // When the last element is rendered
        if (scope.$last) {
            element.parent().parent().trigger('create');
        }
    }
});

fessmodule.$inject = ['$scope'];

听起来像使用旧角度源或与其他来源发生碰撞。

Sounds like you use old angular sources or get collisions with other sources.

希望它能帮到你

这篇关于AngularJs:从DropDown中选择值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 07:28