Javascript 在angularjs中获取服务器数据后未创建DOM

Javascript 在angularjs中获取服务器数据后未创建DOM,javascript,angularjs,model-binding,Javascript,Angularjs,Model Binding,我在前端显示数据时遇到问题 从服务器获取数据后,我无法重新创建表(我使用DWR从服务器获取数据) 单击我在sort()中调用的sort()表格标题时,会调用getObj()函数,该函数进行DWR调用以获取数据 当我点击搜索按钮时,我得到所选选项的值和输入字段值,并通过getObj。。。。。这就是我的问题所在,当我单击表头时,获取的数据会显示出来,但当我单击搜索按钮时,它不会显示出来 这是我的控制器和功能- var searchApp = angular.module('searchApp', [

我在前端显示数据时遇到问题

从服务器获取数据后,我无法重新创建表(我使用DWR从服务器获取数据)

单击我在
sort()
中调用的
sort()
表格标题时,会调用
getObj()
函数,该函数进行
DWR
调用以获取数据

当我点击搜索按钮时,我得到所选选项的值和输入字段值,并通过
getObj
。。。。。这就是我的问题所在,当我单击表头时,获取的数据会显示出来,但当我单击搜索按钮时,它不会显示出来

这是我的控制器和功能-

var searchApp = angular.module('searchApp', []),
    selectData = [];

var inputValue='Yahoo',
    filterValue='0'
searchApp.controller('searchCtrl', function ($scope) {
    $scope.results = [];
    $scope.filterOption=0;
    $scope.filters = [
        {id:1,value:'Campaign'},
        {id:2,value:'Account'},
        {id:3,value:'Publisher Url'},
        {id:4,value:'Email Address'}
    ];

    $scope.obj = [];
    $scope.loaded = false;
    $scope.isSorting = false;
    $scope.inputData='yahoo';

    // Default sort order
    $scope.sortValue = 'categoryId';
    $scope.isSortAsc = false;
    $scope.headList = [
        {
            name: '',
            value: '',
            css: ''
        },
        {
            name: 'Name',
            value: 'value',
            css: 'col-sort-asc'
        },
        {
            name: 'Type',
            value: 'categoryId',
            css: 'col-sort'
        }

    ]          


    // build array
    /*angular.forEach(resultsObj, function (obj, key) {
        /*$scope.filters.push({
            value: key,
            name: obj.label
        });
        for (var i = 0; i < obj.item.length; i++) {
            $scope.results.push({
                label: obj.label,
                name: obj.item[i].name
            });
        } 


    });*/

    $scope.getObj = function() {
        // Add the dialog loader
        dialog.load.init();
        dialog.load.add('search');
        // Make the DWR call
        console.log($scope.isSortAsc,$scope.sortValue,inputValue,filterValue);
        BimDWRLogic.getSearchByCateogry($scope.isSortAsc,$scope.sortValue,inputValue,filterValue, function(obj) {
            $scope.$apply(function() {
                $scope.setObj(obj);
                // Complete the dialog loader
                dialog.load.complete('search');
            });
        });
    };

    // ==================================================
    // Set Object
    // ==================================================
    $scope.setObj = function(obj) {
        $scope.obj = obj;
        console.log('Length is '+$scope.obj.list.length);
        for(i=0;i<$scope.obj.list.length;i++)
        {
            console.log($scope.obj.list[i].categoryId);
            console.log($scope.obj.list[i].value);
        }
        //dialog.load.init();
        //dialog.load.add('performance-summary-chart');
        // Load the chart
        // Sometimes the div is not there
        // TODO: might be a better way of handling this
        // Don't load the chart if we are sorting
        /*if($scope.isSorting !== true){
            window.setTimeout(function(){
                $scope.loadChart();
            }, 500);
        }*/
        $scope.isSorting = false;
        $scope.loaded = true;

    };

    $scope.search=function(){
        inputValue=$scope.inputData;
        console.log('Input value is '+inputValue);

        $scope.getObj();


    }

    $scope.filterCriteria=function(opt){
        $scope.filterOption=opt;
        filterValue=opt;
        console.log('Selected Criteria is '+filterValue);
    }    

    $scope.sort = function(value){

        // Return if the column object is not sortable
        if(value === ''){
            return false;
        }

        // Sets the Data Value
        if(value === $scope.sortValue){
            if($scope.isSortAsc === false){
                $scope.isSortAsc = true;
            }else{
                $scope.isSortAsc = false;
            }
        }else{
            $scope.sortValue = value;
            $scope.isSortAsc = false;
        }

        // Sets the Style
        // Note: we don't loop through the first row
        for(var i=1; i<$scope.headList.length; i++){
            if(value === $scope.headList[i].value){
                if($scope.isSortAsc === true){
                    $scope.headList[i].css = 'col-sort-asc';
                }else{
                    $scope.headList[i].css = 'col-sort-desc';
                }
            }else{
                $scope.headList[i].css = 'col-sort';
            }
        }
        console.log('Inside Sort '+$scope.isSortAsc+' '+$scope.sortValue+' '+inputValue+' '+filterValue);
        // Get the object
        $scope.isSorting = true;
        $scope.getObj();

    };


});
var searchApp=angular.module('searchApp',[]),
选择数据=[];
var inputValue='Yahoo',
filterValue='0'
searchApp.controller('searchCtrl',函数($scope){
$scope.results=[];
$scope.filterOption=0;
$scope.filters=[
{id:1,值:'Campaign'},
{id:2,值:'Account'},
{id:3,值:'Publisher-Url'},
{id:4,值:'Email Address'}
];
$scope.obj=[];
$scope.loaded=false;
$scope.isSorting=false;
$scope.inputData='yahoo';
//默认排序顺序
$scope.sortValue='categoryId';
$scope.isSortAsc=false;
$scope.headList=[
{
名称:“”,
值:“”,
css:'
},
{
姓名:'姓名',
值:“值”,
css:“列排序asc”
},
{
名称:'类型',
值:“categoryId”,
css:“列排序”
}
]          
//构建阵列
/*forEach(结果对象,函数(对象,键){
/*$scope.filters.push({
值:键,
名称:obj.label
});
对于(变量i=0;i该问题与搜索结果html模板中缺少控制器有关。
我认为它会起作用:

<table class="table table-index search-results" ng-controller="searchCtrl">
        <thead>
            <tr class="info">
                <th colspan="3">
                    <div>Filter By:
                        <select ng-model="searchData" ng-options="f.id as f.value for f in filters" class="search-filter" ng-change="filterCriteria(searchData)">
                           <option>--none--</option>
                        </select>
                    </div>
                </th>
            </tr>
            <tr>
               <th ng-repeat="th in headList" class="{{th.css}}" ng-click="sort(th.value)">{{th.name}}</th>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <td colspan="3">&nbsp;</td>
            </tr>
        </tfoot>
        <tbody>
            <tr ng-repeat="resultObj in obj.list">
                <td>{{$index + 1}}.</td>
                <td>{{resultObj.categoryId}}</td>
                <td>{{resultObj.value}}</td>
            </tr>
        </tbody>
    </table>

筛选依据:
--没有--
{{th.name}
{{$index+1}}。
{{resultObj.categoryId}
{{resultObj.value}
但更好的方法是用一个标记包装您的部分,并使用一个控制器声明

<table class="table table-index search-results" ng-controller="searchCtrl">
        <thead>
            <tr class="info">
                <th colspan="3">
                    <div>Filter By:
                        <select ng-model="searchData" ng-options="f.id as f.value for f in filters" class="search-filter" ng-change="filterCriteria(searchData)">
                           <option>--none--</option>
                        </select>
                    </div>
                </th>
            </tr>
            <tr>
               <th ng-repeat="th in headList" class="{{th.css}}" ng-click="sort(th.value)">{{th.name}}</th>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <td colspan="3">&nbsp;</td>
            </tr>
        </tfoot>
        <tbody>
            <tr ng-repeat="resultObj in obj.list">
                <td>{{$index + 1}}.</td>
                <td>{{resultObj.categoryId}}</td>
                <td>{{resultObj.value}}</td>
            </tr>
        </tbody>
    </table>