在AngularJS中插入后重新加载列表
reloading list after insert in AngularJS
我正在执行插入和更新,在单词后面我想重新加载项目列表,但它在视图中复制了它。
这是的加载函数
// Listing contact resources
$scope.load = function () {
var g = $rdf.graph();
var f = $rdf.fetcher(g);
f.nowOrWhenFetched($scope.path + '*',undefined,function(){
var DC = $rdf.Namespace('http://purl.org/dc/elements/1.1/');
var RDF = $rdf.Namespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#');
var LDP = $rdf.Namespace('http://www.w3.org/ns/ldp#');
//var myOntology = $rdf.Namespace('http://user.pds.org/ontology/');
var VCARD = $rdf.Namespace('http://www.w3.org/2006/vcard/ns#');
var evs = g.statementsMatching(undefined, RDF('type'), VCARD('Individual'));
if (evs != undefined) {
for (var e in evs) {
var id = evs[e]['subject']['value'];
var fullname = g.anyStatementMatching(evs[e]['subject'], VCARD('fn'))['object']['value'];
var email = g.anyStatementMatching(evs[e]['subject'], VCARD('hasEmail'))['object']['value'];
var phone = g.anyStatementMatching(evs[e]['subject'], VCARD('hasTelephone'))['object']['value'];
var contact = {
id: id.slice(id.length-1),
fullname: fullname,
email: email,
phone: phone
};
$scope.contacts.push(contact);
$scope.$apply();
}
}
});
};
这是插入/更新功能
// Function to insert or update a contact resource
$scope.insertContact = function (contact) {
var uri = $scope.path + $scope.prefix + contact.id;
var resource = $scope.composeRDFResource(contact, uri);
$http({
method: 'PUT',
url: uri,
data: resource,
headers: {
'Content-Type': 'text/turtle',
'Link': '<http://www.w3.org/ns/ldp#Resource>; rel="type"'
},
withCredentials: true
}).
success(function(data, status, headers) {
if (status == 200 || status == 201) {
console.log('Success: Resource created.');
// Update view
$scope.load();
}
}).
error(function(data, status) {
if (status == 401) {
console.log('Forbidden: Authentication required to create new resource.');
} else if (status == 403) {
console.log('Forbidden: You are not allowed to create new resource.');
} else {
console.log('Failed '+ status + data);
}
});
};
两者都能正常工作,但当在插入中调用load时,它会将重新加载的新项目与列表中的旧项目一起添加。
在重新加载之前/期间清空列表的位置?
谢谢,
您应该在"加载"新项目之前清空列表。
.success(function(data, status, headers) {
if (status == 200 || status == 201) {
console.log('Success: Resource created.');
// Update view
$scope.contacts.length = 0;
$scope.load();
}
})
您可以在开始$scope.load函数时清空联系人列表,即:
$scope.load = function () {
//here
$scope.contacts = []
var g = $rdf.graph();
var f = $rdf.fetcher(g);
...
}
但我建议你只将新联系人添加到列表中,而不是在你的成功回电更新后重新加载所有列表
success(function(data, status, headers) {
if (status == 200 || status == 201) {
console.log('Success: Resource created.');
// Update view
//instated of reloading all list
//$scope.load();
//just add new contact
$scope.push(contact)
}
}
相关文章:
- 如何根据对具有多行的先前列表的选择来动态加载下拉列表
- Netsuite Suitelet:在不达到治理限制的情况下,遍历事务行项目的列表加载和提交记录
- 如何在页面加载后禁用下拉列表框项目的选择
- 从要使用Protractor测试的服务器异步加载的动态数据列表的列表
- 网页上已有tinymce加载图像列表
- 在本地存储中选中复选框,但在加载时也要筛选列表
- 如果使用jquery在页面加载时未选择任何选项,如何禁用下拉列表
- 在AngularJS中插入后重新加载列表
- 在加载列表时定义 dhtmlxList 的 ID 值
- 基于值 json 请求的加载列表
- 如何在加载列表框时选择第一项
- 加载列表(带图像)时添加回调函数
- 显示预加载列表(Spring+JSP)中的数据
- jQuery Mobile延迟加载列表项
- 选择2按类型搜索预加载列表
- 从模型MVC 4中动态加载列表
- Ng-重复重复$index在选择列表中 编辑:Ng 重复不会加载列表中的所有值
- ExtJS 网格过滤器:如何从外部 JSON 加载“列表”过滤器选项
- AngularJs的延迟加载列表记住数据
- 如何使用onclick()延迟加载列表项