我的HTML代码:
<div class="col-lg-8">
{{Item.CotoNombre}}
<select id="PaisId" ui-select2="select2Relative(Item)" ng-model="PaisId" class="select2-single form-control">
<option value="iphone4">iPhone 4</option>
<option value="iphone5">iPhone 5</option>
<option value="iphone6">iPhone 6</option>
</select>
</div>
这是我的带有ui-select2功能的控制器:
'use strict';
app.controller('AppController', function($scope, $controller, $rootScope, $state, $stateParams, AppFactory, AuthFactory, CRUD_CONFIG) {
angular.extend(this, $controller('CoreController', {$scope: $scope}));
$scope.AppPermalink = $stateParams.AppPermalink;
$scope.init = function() {
$scope.getApp();
switch($state.current.name){
case "appedit":
$scope.getItem();
break;
}
}
/**
* [Obtener informacion de aplicacion]
*/
$scope.getApp = function() {
AppFactory.Applications($stateParams.AppPermalink).success(function(data) {
$rootScope.App = data[0];
$scope.AppPermalink = data[0].Permalink;
$scope.getResults();
}).error(function() {
//No se ha encontrado la app 404
});
}
/**
* [Listar registros]
*/
$scope.getResults = function() {
AppFactory.Items($stateParams.AppPermalink).success(function(data) {
$scope.Results = data.data;
$scope.ResultsCount = data.total;
}).error(function() {
$scope.ResultsCount = 0;
});
}
/**
* Ficha de registro
*/
$scope.getItem = function() {
AppFactory.Item($stateParams.AppPermalink, $stateParams.ItemId).success(function(data) {
$scope.Item = data.data[0];
}).error(function() {
//No se ha encontrado la app 404
});
}
/**
* [Eliminar registro]
* @param {int} Item [Registro]
*/
$scope.removeItem = function(Item) {
AppFactory.RemoveItem($scope.Permalink, Item._EntityId).success(function(data) {
var index = $scope.Results.indexOf(Item);
$scope.Results.splice(Item, 1);
}).error(function() {
//Error al borrar
});
}
$scope.select2Relative = function(Field) {
console.log(Field);
return {
multiple: true,
ajax: {
url: CRUD_CONFIG.apiUrl+"/"+CRUD_CONFIG.appFarm+"/apps/get/" + $stateParams.AppPermalink,
method: "GET",
dataType: 'json',
data: function (term, page) {
return {
filters: "{\""+Field+"\": {\"type\": 4, \"string\": "+term.term+"}}",
page: page
};
},
results: function (data, page) {
return {results: data};
}
},
formatResult: function(object, container, query) {
return object.name;
}
}
}
/**
* [Obtener valor de campo segun su tipo]
* @param {[type]} Field [Campo de aplicacion]
* @param {[type]} Result [Registro]
*/
$scope.renderValueField = function(Field, Result) {
if(Field.Type.lastIndexOf("[")>0){
var FieldType = Field.Type.substring(0,Field.Type.lastIndexOf("["));
}else{
var FieldType = Field.Type;
}
switch(FieldType){
case "relative":
var Vars = angular.fromJson(Field.Vars);
return Result[Field.Name][Vars.relative];
break;
case "multiple_relative":
var Vars = angular.fromJson(Field.Vars);
var res = "";
angular.forEach(Result[Field.Name], function(value, key) {
res = res + value[Vars.relative]+", ";
});
return res.trim().substring(0,(res.length - 2));
break;
default:
return Result[Field.Name];
}
}
$scope.init();
});
字段是未定义的变量但不应该。 “Item.CotoNombre”打印我的值,但是ui-select2无法获得参数。
我需要传递一个dinamic url和params到我的ajax调用,我不知道其他方法。
我做错了什么?