AngularJS智能表文档/演示车是否存在错误? [英] Is the AngularJS smart-table documentation/demo buggy?

查看:55
本文介绍了AngularJS智能表文档/演示车是否存在错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是不明白这一点.在智能表网页上,该页面讨论了 stSafeSrc属性,我看不到 $ scope所在的位置.显示收藏被声明.

I just don't understand this. On the smart-table web page, where it discusses the stSafeSrc attriubute, I don’t see where $scope. displayedCollection gets declared.

文字说, smart-table首先会为您显示的收藏集创建一个安全副本,然后我

我以为是一个智能表指令在声明它,但是示例代码对我不起作用–表行为空–这对我来说就是问题所在.

I had assumed that a smart-table directive was declaring it, but the sample code won’t work for me – the table rows are empty - and that’s what looks to me to be the problem.

例如,如果我们查看对问题,我们看到用户将 $ scope.displayedCollection 声明为一个空数组,并在收到AJAX响应时为其分配一个值.但是文档没有提及.

If we look, for instance, at the accepted answer to this question, we see the user declaring $scope.displayedCollection as an empty array and assigning it a value when the AJAX response is received. BUT, the documentation doesn't mention that.

<table st-table="displayedCollection" st-safe-src="rowCollection">
      <thead>
        <tr>
          <th st-sort="firstName">First Name</th>
          <th st-sort="lastName">Last Name</th>
        </tr>
      </thead>
      <tbody>
        <tr ng-repeat="row in displayedCollection">
          <td>{{row.firstName}}</td>
          <td>{{row.lastName}}</td>
        </tr>
      </tbody>
</table


app.controller('Ctrl', function($scope, service) {
    $scope.displayedCollection = [];

    service.all.then(function(list) {
        $scope.rowCollection = list;
        $scope.displayedCollection = list;
    });
});

那么,我需要自己照顾副本吗?是否需要更新文档?演示如何工作?

So, do I need to care for the copy myself? And does the documentaion need to be updated? And how does the demo work?

[更新]我在 github问题上找到了这个,@tufan-yoc

[Update] I find this on the github issues, by @tufan-yoc

您必须将数据数组复制到范围中的另一个变量:

you have to copy the data array to an other variable in the scope:

st-table="displayedCollection" st-safe-src="rowCollection"

 //copy the references (you could clone ie angular.copy   
 // but then have to go through a dirty checking for the matches)
    $scope.displayedCollection = [].concat($scope.rowCollection);

如果这确实是一个要求,为什么没有明确记录呢?

If this truly is a requirement, why is it not explictly documented?

为什么没有它在智能表网站上的示例可以工作?

And why does the example on the smart-table website work without it?

推荐答案

您无需复制任何内容.您使用属性st-table设置的内容只是模板的占位符(即作用域中的变量),您可能会在行中继器中使用它,而不必在任何地方声明,智能表将为其分配项目要显示给该变量,以便可以更新您的模板.

You don't need to copy anything. what you set with the attribute st-table is simply a placeholder for your templates (ie a variable in the scope) which you will likely use in the row repeater, it does not have to be declared anywhere, smart-table will assign the items to be displayed to this variable so your templates can be updated.

您的真实来源(即您的数据)应该是您绑定到st-safe-src属性的集合.每当绑定的集合发生更改时,智能表都会更新本地副本,以便它可以根据最新数据和实际数据执行过滤器/排序/切片操作.

your source of truth (ie your data) should be the collection you bind to st-safe-src attribute. Whenever the bound collection changes, smart table will update a local copy so it can perform the filter/sort/slice operations based on the latest and actual data.

但是,为了方便起见(和提高性能),如果您不打算修改数据(或者不像ajax fetch那样延迟其到达时间),则内部副本首先基于绑定到设计范围内的变量的任何集合通过st-table属性.请注意,在这种情况下,该值将被擦除,并由显示的集合替换,因此将更新模板.幸运的是,初始副本将作为智能表的私有变量保留.

However for convenience (and performance), if you don't intend to modify your data (or its arrival is not delayed like with ajax fetch) the internal copy is firstly based on any collection bound to the variable in the scope designed by the st-table attribute. Note in this case, the value will be erased and replaced by the displayed collection so the template is updated. Fortunately the initial copy will persist as private variable of smart-table.

如果遇到问题,则可能来自其他地方.如果是这样,请提供一个运行示例(包含角度版本和智能表版本)

If you encounter a problem it likely comes from somewhere else. If so please provide a running example (with angular version and smart table version)

这篇关于AngularJS智能表文档/演示车是否存在错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆