2016-04-07 25 views
3

Bu bileşene https://github.com/alexklibisz/angular-dual-multiselect-directive ürününü kullanmayı deniyorum ama verileri arka uçtan bileşene nasıl geçirebilirim bilmiyorum.Değişken değişkenini başka bir değişkende kullanın.

Ben arka uç veri almak:

var vm = this; 
vm.Categoria1 = []; 
$http.get('http://localhost:5541/api/date/ListCategorii').success(function (data) { 
    vm.Categoria1 = data; 
} 
); 

Ben veri almak:

[{"Id":1,"NumeCategorie":"Fructe"},{"Id":2,"NumeCategorie":"Legume"},{"Id":3,"NumeCategorie":"Ciocolata"}] 

ama vm.Categoria1 boş aşağıda:

$scope.demoOptions = { 
    title: 'Demo: Recent World Cup Winners', 
    filterPlaceHolder: 'Start typing to filter the lists below.', 
    labelAll: 'All Items', 
    labelSelected: 'Selected Items', 
    helpMessage: ' Click items to transfer them between fields.', 
    /* angular will use this to filter your lists */ 
    orderProperty: 'name', 
    /* this contains the initial list of all items (i.e. the left side) */ 
    items: vm.Categoria1, //[{ 'id': '50', 'name': 'Germany' }, { 'id': '45', 'name': 'Spain' }, { 'id': '66', 'name': 'Italy' }, { 'id': '30', 'name': 'Brazil' }, { 'id': '41', 'name': 'France' }, { 'id': '34', 'name': 'Argentina' }], 
    /* this list should be initialized as empty or with any pre-selected items */ 
    selectedItems: [] 
}; 

teşekkür ederiz .

+0

demoOptions'u ayarladığınız anda vm.Categoria1 kümeniz var mı? $ Http araması senkronize olmadığından, demoOptions nesnesini başlattıktan sonra yalnızca sonuçları alabilirsiniz. –

cevap

1

iyi uygulama böyle kullanmaktır:

var vm = this; 
vm.Categoria1 = []; 

$http.get('http://localhost:5541/api/date/ListCategorii') 
.success(function(data) { 
    vm.Categoria1 = data; 
    $scope.demoOptions = { 
    title: 'Demo: Recent World Cup Winners', 
    filterPlaceHolder: 'Start typing to filter the lists below.', 
    labelAll: 'All Items', 
    labelSelected: 'Selected Items', 
    helpMessage: ' Click items to transfer them between fields.', 
    /* angular will use this to filter your lists */ 
    orderProperty: 'name', 
    /* this contains the initial list of all items (i.e. the left side) */ 
    items: vm.Categoria1, //[{ 'id': '50', 'name': 'Germany' }, { 'id': '45', 'name': 'Spain' }, { 'id': '66', 'name': 'Italy' }, { 'id': '30', 'name': 'Brazil' }, { 'id': '41', 'name': 'France' }, { 'id': '34', 'name': 'Argentina' }], 
    /* this list should be initialized as empty or with any pre-selected items */ 
    selectedItems: [] 
}) 
.error(function(data, status) { 
    console.error('Repos error', status, data); 
}) 
.finally(function() { 
    console.log("finally finished repos"); 
}); 

Umut yardımcı olur! Sa-mi spui daca ai probleme.

1

Sen başarı geri aramasında demoOptions ayarlamanız gerekir:

var vm = this; 
vm.Categoria1 = []; 
$http.get('http://localhost:5541/api/date/ListCategorii').success(function (data) { 
     vm.Categoria1 = data; 
     $scope.demoOptions = { 
     title: 'Demo: Recent World Cup Winners', 
     filterPlaceHolder: 'Start typing to filter the lists below.', 
     labelAll: 'All Items', 
     labelSelected: 'Selected Items', 
     helpMessage: ' Click items to transfer them between fields.', 
     /* angular will use this to filter your lists */ 
     orderProperty: 'name', 
     /* this contains the initial list of all items (i.e. the left side) */ 
     items: vm.Categoria1, //[{ 'id': '50', 'name': 'Germany' }, { 'id': '45', 'name': 'Spain' }, { 'id': '66', 'name': 'Italy' }, { 'id': '30', 'name': 'Brazil' }, { 'id': '41', 'name': 'France' }, { 'id': '34', 'name': 'Argentina' }], 
     /* this list should be initialized as empty or with any pre-selected items */ 
     selectedItems: [] 
    }; 
}); 
0

isteğin başarısında öğeleri belirlesin:

$http.get('http://localhost:5541/api/date/ListCategorii') 
    .success(function (data) { 
      $scope.demoOptions.items = vm.Categoria1 = data;    
     }); 
1

Diğer seçenek ise, bir işlev oluşturabilirsiniz http.get çağrı ve sayfa yük üzerinde bu işlevi dediğimiz içerir:

var vm = this; 
vm.Categoria1 = []; 

var onload = function(){ 
    $http.get('http://localhost:5541/api/date/ListCategorii').success(function (data) { 
     vm.Categoria1 = data; 
    } 
}; 

$scope.demoOptions = { 
    title: 'Demo: Recent World Cup Winners', 
    filterPlaceHolder: 'Start typing to filter the lists below.', 
    labelAll: 'All Items', 
    labelSelected: 'Selected Items', 
    helpMessage: ' Click items to transfer them between fields.', 
    /* angular will use this to filter your lists */ 
    orderProperty: 'name', 
    /* this contains the initial list of all items (i.e. the left side) */ 
    items: vm.Categoria1, //[{ 'id': '50', 'name': 'Germany' }, { 'id': '45', 'name': 'Spain' }, { 'id': '66', 'name': 'Italy' }, { 'id': '30', 'name': 'Brazil' }, { 'id': '41', 'name': 'France' }, { 'id': '34', 'name': 'Argentina' }], 
    /* this list should be initialized as empty or with any pre-selected items */ 
    selectedItems: [] 
}; 

onload(); 
İlgili konular