javascript - AngularJs:从下拉列表中选择值

标签 javascript jquery jquery-mobile angularjs

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

我的 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部分

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="false" data-role="listview"然后代码工作正常

请帮帮我

我的示例的演示页面是 Here

最佳答案

您可以在 Fiddle 中找到工作代码

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'];

听起来您使用旧的 Angular 源或与其他源发生碰撞。

希望对你有帮助

关于javascript - AngularJs:从下拉列表中选择值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18911458/

相关文章:

jquery - 使用 jQuery 调整 div 中所有元素的大小

javascript - 在移动设备上显示图像的标题

jquery - 如何使用 jQuery 和 jQuery 模板基于嵌套 JSON 数据创建嵌套 ListView 。

javascript - 以十进制显示 2 个数字的总和

javascript - 以 "@"开头的 JS 变量

javascript - 如何重置 Highcharts 中图例区域的项目?

jquery - jQM页脚在转换前后消失和出现

javascript - 如何限制数据表行的选择?

javascript - Google Maps API V3 - 在边界内最近的路线

javascript - 处理jquery中的滑动?