【发布时间】:2013-11-08 10:06:18
【问题描述】:
我在我的项目中使用Siyfion's typeahead directive。
我在控制器中所做的事情是这样的:
$http({method: 'GET', 'url': CONFIG.SOMEURL})
.success(function(data, status, headers , config){
if(status==200)
{
$scope.objects = data;
for(i=0; i < $scope.objects.length; i++){
$scope.allObjects.push($scope.objects[i].name);
}
console.log($scope.allObjects);
$scope.dataSet = {
name : 'objs',
local : $scope.allObjects
};
我从django 视图中得到一个“对象”数组作为 json。但问题出在我的 HTML 模板中:
<input type="text" class='sfTypeahead' datasets='dataSet' ng-model='testname' />
由于在进行异步调用时 dataSet 最初是空的,所以我收到一个错误:
TypeError: Cannot read property 'name' of undefined
如果我可以在dataSet 或datasets 中查找更改,是否有办法在数组allObjects 被填充后,DOM 可能会被刷新?
任何人都可以建议在这里可以做什么
【问题讨论】:
-
只需使用 angular-ui.github.io/bootstrap/#/typeahead 代替它与这里描述的 Promise 一起工作:stackoverflow.com/a/15930592/1418796
-
支持bs3吗?我目前正在使用 bs3。
-
是的,它应该可以毫无问题地与 BS3 一起使用
-
感谢您的链接。会读一读:)
-
@pkozlowski.opensource。感谢您的资源。是否有很好的阅读可以帮助我了解承诺如何与指令一起使用?我的意思是我应该如何编写我的指令,以便它将返回承诺的函数作为其输入?
标签: javascript django angularjs typeahead.js