我的dom不反映我的模型更新值,更新是由一个函数,这是按钮单击CAL完成的

my dom is not reflecting my model updated value, updationg is done by a function which is cal on button click

本文关键字:我的 更新 函数 一个 单击 按钮 CAL dom 模型      更新时间:2023-09-26
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
        }
    };
})

在作用域上使用这样的方法,您应该将其用于ng-click

<button ng-click="SortCustomer()">click me</button>

虽然这里在JS中不是传递searchitem作为参数你应该使用模型分配给你使用的任何输入

$scope.SortCustomer = function (searchitem) {

我可以更具体地回答,只要你做一个plunker或jsfiddle

欢呼