这是使用PHP生成的json
[{"Sale":{"id":"1","customer_id":"1","amount":"15","created":"2014-05-17"}}]
Run Code Online (Sandbox Code Playgroud)
做orderBy:id的显然不起作用.我在其他帖子中读到需要为这种数据结构创建orderBy函数.我无法创建该功能.任何人都可以告诉我这是正确的方法吗?
这是我的代码
<a href="" ng-click="predicate = 'productname'; reverse=false">Productname</a>
<a href="" ng-click="predicate = 'productprice'; reverse=false">Productprice</a>
Run Code Online (Sandbox Code Playgroud)
迭代
<div ng-repeat="sale in sales | orderBy:customSort">
Run Code Online (Sandbox Code Playgroud)
海关功能
$scope.customSort = function(sale) {
};
Run Code Online (Sandbox Code Playgroud)
目前在customSort函数中,我得到了所有的销售数据,但我也希望将谓词值传递给函数,以便它可以进行相应的排序(如果点击名称,则按名称排序,如果单击价格谓词,则按价格排序.)
如何将谓词值传递给customSort函数?任何人都可以帮我这个吗?谢谢.
这是我的控制器代码:
var selectableFields = ["customerName", "customerAddress"];
angular.forEach(selectableFields, function(field, key) {
var value = $.jStorage.get(field); //using jStore to get the values
$scope.field=value;
});
Run Code Online (Sandbox Code Playgroud)
目标是能够在视图中访问{{customerName}}和{{customerAddress}}.任何人都可以告诉我这样做的正确方法是什么?
试图学习AngulareJS一直坚持这一点.
这是代码:
app.config(function ($routeProvider){
$routeProvider
.when('/',
{
templateUrl: '/sort',
controller : 'tasksController'
})
.when('/expression/:expressionId/type/:typeId',
{
templateUrl: '/sort/'+:expressionId +'/'+ :typeId,
controller : 'tasksController'
})});
Run Code Online (Sandbox Code Playgroud)
这显然是错误的.
请问任何人请告诉我这样做的正确方法是什么?谢谢.