Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/401.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 安圭拉酒店;Datatable-重新呈现单元格值时编译html_Javascript_Jquery_Angularjs_Datatable_Angularjs Directive - Fatal编程技术网

Javascript 安圭拉酒店;Datatable-重新呈现单元格值时编译html

Javascript 安圭拉酒店;Datatable-重新呈现单元格值时编译html,javascript,jquery,angularjs,datatable,angularjs-directive,Javascript,Jquery,Angularjs,Datatable,Angularjs Directive,我正在使用angularjs和datatable构建一个网格。我有以下javascript代码 演示: datatable\u config={ “bJQueryUI”:没错, “bProcessing”:正确, “bDeferRender”:没错, “sDom”:“Rlfrtip”, “aaData”:[null] }; angular.forEach(列、函数(列、键){ datatable_config.aoColumns.push({ “缝合”:column.displayName, “

我正在使用angularjs和datatable构建一个网格。我有以下javascript代码

演示:

datatable\u config={
“bJQueryUI”:没错,
“bProcessing”:正确,
“bDeferRender”:没错,
“sDom”:“Rlfrtip”,
“aaData”:[null]
};
angular.forEach(列、函数(列、键){
datatable_config.aoColumns.push({
“缝合”:column.displayName,
“mData”:函数(源、类型、值){
变量单元格_值=(源[column.field])?源[column.field]:'',呈现的_单元格;
如果(column.field=='something'){
呈现的_cell=$compile('{{$root.value}}}')($scope);
/*对于本专栏,我没有得到带有求值根范围的span元素,而是说[object]*/
}否则{
渲染单元=单元值;
}
返回U单元;
}
});
});
当我编译HTML时,它显示
[object object]
。我遇到了这个问题,我们需要在绑定后编译它,比如
element.html(value)$编译(element.contents())(范围)。但是在上面的代码中是不可能的。有什么解决办法或想法吗

谢谢你的建议。

试试这个

$scope.tableData = []; // just initialize an array to store data coming from server

      // watch each change in the server-side data to reload grid table
      $scope.$watch("tableData", function (data) {
        $scope.tableParams.reload();
      });

      // Set ng-table parameters with pagination
        $scope.tableParams = new ngTableParams({
          page: 1,      // show first page
        count: 10     // count per page
      }, {
        total: $scope.tableData.length, // length of data
        $scope: {},
        getData: function($defer, params) {
          var filteredData = $scope.tableData;
          // use build-in angular filter
          var orderedData = params.sorting() ? $filter('orderBy')(filteredData, params.orderBy()) : filteredData;
          orderedData = params.filter() ? $filter('filter')(orderedData, params.filter()) : orderedData;
          params.total(orderedData.length); // set total for recalc pagination
          $defer.resolve($scope.results = orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
        }
      });
桌子应该是这样的

<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered datatables"  ng-table="tableParams"  show-filter="true">
   <tbody>
      <tr ng-repeat="tableData in $data">
         <!-- Checkbox -->
         <td data-title="''"  class="center" header="'ng-table/headers/checkbox.html'" width="4">
            <input type="checkbox" ng-model="checkboxes.items[tableData.id]" />
         </td>
         <!-- name-->
         <td data-title="some title" sortable="'name'" filter="{ 'name': 'text' }">
            <span ng-if="!tableData.$edit">{{tableData.name}}</span> <!--here name should be as same field as in data base-->
         </td>
   </tbody>
</table>

{{tableData.name}

在编译“要呈现的DOM”时遇到类似问题。 几个小时后,虽然我的要求大不相同,但最终还是成功了。 我还需要绑定指令,为此需要使用$compile()

对于您的用例, 使用$parse

// parse the "value" attribute value into a function
var parseFn = $parse(value);
// "parseFn" is a function that can be invoked to get the expression's value 
// providing a scope
var currVal = parseFn($root);

// return updated markup
return '<span>'+ currVal +'</span>';
//将“value”属性值解析为函数
var parseFn=$parse(值);
//“parseFn”是一个可以调用以获取表达式值的函数
//提供范围
var currVal=parseFn($root);
//返回更新的标记
返回“”+当前值+“”;

我认为有点晚了,但我有一个更简单的解决方案来解决这个问题,但我仍然建议您使用angular datatable指令

data_table.directive('dataTable', ['$log', '$timeout', '$compile', function($log, $timeout, $compile){
return {
    restrict: 'C',
    controller : ['$rootScope', '$scope', '$element', function ($rootScope, $scope, $element){
        var grid_table, 
        datatable_config = {
            "bJQueryUI": true,
            "bProcessing": true,
            "bDeferRender": true,
            "sDom": "Rlfrtip",
            "aaData": [
              {'name': 'Aravind'}
            ]
        };

        datatable_config.aoColumns = [];

        datatable_config.aoColumns.push({
            "sTitle": 'Name', 
            "mData": function(source, type, value){
                //No need to compile the value
                var direct = '<span>' + source.name +'</span>';
                return  direct;
            }
        });

        grid_table = $element.dataTable(datatable_config);
    }]
}
data\u table.directive('dataTable',['$log','$timeout','$compile',函数($log,$timeout,$compile){
返回{
限制:“C”,
控制器:['$rootScope','$scope','$element',函数($rootScope,$scope,$element){
var grid_表,
数据表配置={
“bJQueryUI”:没错,
“bProcessing”:正确,
“bDeferRender”:没错,
“sDom”:“Rlfrtip”,
“aaData”:[
{'name':'Aravind'}
]
};
datatable_config.aoColumns=[];
datatable_config.aoColumns.push({
“针”:“名称”,
“mData”:函数(源、类型、值){
//无需编译该值
var direct=''+source.name+'';
直接返回;
}
});
grid_table=$element.dataTable(dataTable_config);
}]
}
}]))


谢谢,我希望这可以帮助其他人。

仅供参考,我正在使用jQuery datatable。。。
data_table.directive('dataTable', ['$log', '$timeout', '$compile', function($log, $timeout, $compile){
return {
    restrict: 'C',
    controller : ['$rootScope', '$scope', '$element', function ($rootScope, $scope, $element){
        var grid_table, 
        datatable_config = {
            "bJQueryUI": true,
            "bProcessing": true,
            "bDeferRender": true,
            "sDom": "Rlfrtip",
            "aaData": [
              {'name': 'Aravind'}
            ]
        };

        datatable_config.aoColumns = [];

        datatable_config.aoColumns.push({
            "sTitle": 'Name', 
            "mData": function(source, type, value){
                //No need to compile the value
                var direct = '<span>' + source.name +'</span>';
                return  direct;
            }
        });

        grid_table = $element.dataTable(datatable_config);
    }]
}