我的dom没有反映我的模型更新值,updationg由按钮点击时的cal函数完成

时间:2014-06-15 15:37:12

标签: javascript jquery html5 angularjs

app.controller('thumbnailController', function ($scope) {
    debugger
    $scope.customers = [
                  { name: 'ave Jones', city: 'Phoenix' },
                  { name: 'amie Riley', city: 'Phoenix' }

    ];
    $scope.SortCustomer = function (searchitem) {
        $scope.customers = [
              { name: 'ave Jones', city: 'Phoenix' },
              { name: 'amie Riley', city: 'Phoenix' }
        ];
        if (searchitem != 'all') {
            var filter = [];
            var items = $scope.customers;
            //  $scope.angular.forEach
            var i = 0;
            for (i; i < 7; i++) {
                if (items[i].name[0] === searchitem) {
                    console.log('pushing');
                    filter.push(items[i]);
                }
            }
            $scope.customers = filter;  // I have update my customers list hear but it not reflecting on dom
        }

    };
})

1 个答案:

答案 0 :(得分:0)

使用类似于范围的方法,您应该将其与ng-click

一起使用
<button ng-click="SortCustomer()">click me</button>

虽然在JS中没有将searchitem作为参数传递,但您应该使用分配给您正在使用的输入的模型

$scope.SortCustomer = function (searchitem) {

一旦你做了一个探索者或者jsfiddle,我就能回答更具体的问题

干杯