- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
下午好!
我正在尝试使用 UI-Select 来填充与模型关联的表单。使用 Controller 以下列方式从服务器接收模型数据:
<form action="index.php" method="post" class="form-horizontal" ng-controller="WorkPlanController as ctrl" ng-init="init(6)">
<!-- this work perfectly! -->
<textarea name="workplan_approver_post" ng-model="workplan.approver_post"></textarea>
<!-- here I have troubled -->
<div ng-controller="LookupController as lookupCtrl" ng-init="lookupCtrl.initLookup('corriculum_speciality_directions')">
<ui-select ng-disabled="disabled" multiple ng-model="workplan.profiles" theme="select2">
<ui-select-match placeholder="Выберите значение из списка">{{$item.value}}</ui-select-match>
<ui-select-choices repeat="item.key as item in items track by $index | filter: $select.search">
<div ng-bind-html="item.value | highlight: $select.search"></div>
</ui-select-choices>
</ui-select>
</div>
</form>
WorkPlanController 是一个简单的 REST 服务:
application
.controller("WorkPlanController", [
'$scope',
'WorkPlan',
function($scope, workPlanFactory){
$scope.workplan;
$scope.workplan = {
profiles: []
};
$scope.init = function($id){
workPlanFactory.get({id: $id}, function(data){
$scope.workplan = data;
});
};
$scope.save = function(){
$scope.workplan.$save();
}
}]);
application
.factory('WorkPlan', function($resource){
return $resource(web_root + "_modules/_corriculum/workplans.php", {
model: "CWorkPlan",
type: "json"
}, {
get: {
method: "GET",
params: {
id: '@id',
action: "get"
}
}
});
});
服务器以下列方式获取 WorkPlan 对象:
{"id":"5","title":"title","department_id":"0","approver_post":"","approver_name":"","discipline_id":"402","corriculum_discipline_id":"566","direction_id":"79","qualification_id":"220","education_form_id":"0","year":"2015","author_id":"311","profiles":[]}
我还使用了一个相同的 LookupController:
application
.factory("LookupCatalog", function($resource){
return $resource(web_root + "_modules/_search/", {
}, {
query: {
method: "GET",
isArray: true,
params: {
catalog: '@catalog',
action: "NgLookupViewData"
}
}
});
})
.controller("LookupController", [
'$scope',
'LookupCatalog',
function ($scope, lookupCatalog) {
$scope.items;
this.initLookup = function (glossary) {
lookupCatalog.query({catalog: glossary}, function(data) {
$scope.items = data;
});
}
}
]);
LookupController 以下列形式接收数据:
[{"key":429,"value":"data1"},{"key":430,"value":"data2"},{"key":1743,"value":"data3"},{"key":1744,"value":"data4"},{"key":1852,"value":"data5"}]
一切看起来都不错,然后 ng-model workplan.profiles 属性为空:
然后我将数据保存到服务器,Angular 发送带有以下数据的 POST:
{"id":"5","title":"title","department_id":"0","approver_post":"","approver_name":"","discipline_id":"402","corriculum_discipline_id":"566","direction_id":"79","qualification_id":"220","education_form_id":"0","year":"2015","author_id":"311","profiles":[430,430]}
我明白了,配置文件是键的数组,并且格式正确。但是当我尝试将这些数据加载回模型并填充表单时,我遇到了很多 js 错误:
Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: $item in $select.selected, Duplicate key: undefined:undefined, Duplicate value: undefined
http://errors.angularjs.org/1.3.2/ngRepeat/dupes?p0=%24item%20in%20%24select.selected&p1=undefined%3Aundefined&p2=undefined
at REGEX_STRING_REGEXP (angular.js:80)
at ngRepeatAction (angular.js:24167)
at Object.$watchCollectionAction [as fn] (angular.js:13909)
at Scope.$get.Scope.$digest (angular.js:14042)
at Scope.$get.Scope.$apply (angular.js:14304)
at angular.js:16035
at completeOutstandingRequest (angular.js:4842)
at angular.js:5215
angular.js:11383 TypeError: Cannot read property 'search' of undefined
at uis.directive.link.ngModel.$formatters.unshift.checkFnMultiple (angular-select.js:1111)
at Array.<anonymous> (angular-select.js:1125)
at Object.ngModelWatch (angular.js:20669)
at Scope.$get.Scope.$digest (angular.js:14034)
at Scope.$get.Scope.$apply (angular.js:14304)
at done (angular.js:9518)
at completeRequest (angular.js:9703)
at XMLHttpRequest.requestLoaded (angular.js:9646)
http://dl2.joxi.net/drive/0009/3267/613571/150315/90c1afa060.jpg
但我已经在 ui-select-choices 的重复中添加了按条件跟踪!我应该怎么做才能使其正常工作?
最佳答案
我不确定您将如何从 php 获取信息,因为我的做法略有不同,但以下代码是一种使用简单的 ng-repeat 和 js 文件中的 track by 和 $scope 数组的方法。
ng-repeat 可以以相同的方式用于许多不同的元素。
这是使用 $scope.choice 数组列出下拉列表中的元素和选择元素的简单方法
如果您可以将您的信息返回到 $scope 变量,那么这应该对您有帮助
<div ng-controller="DropdownCtrl">
<!-- Single button -->
<div class="btn-group" uib-dropdown is-open="status.isopen">
<button id="single-button" type="button" class="btn btn-primary" uib-dropdown-toggle ng-disabled="disabled">
Button dropdown <span class="caret"></span>
</button>
<ul class="uib-dropdown-menu" role="menu" aria-labelledby="single-button">
<li ng-repeat="choice in items track by $index">
<a href>{{choice}}</a>
</li>
</ul>
</div>
<select>
<option ng-repeat="choice in items track by $index">{{choice}}</option>
</select>
</div>
$scope.items = [
'The first choice!',
'The first choice!',
'And another choice for you.',
'but wait! A third!'
];
关于javascript - AngularJS 和 UI-Select multiple with data,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29060696/
只是想知道这些结构之间有什么区别(text、data、rodata、bss 等)在链接描述文件中: .data : { *(.data) } .data : { *(.data*) }
Data 定义为其核心功能之一 gfoldl : gfoldl :: (Data a) => (forall d b. Data d => c (d -> b) -> d -> c b)
以下之间有什么区别:data-sly-use、data-sly-resource、data-sly-include 和 数据-sly-模板?我正在阅读 Sightly AEM 上的文档,我非常困惑。
我有一个 Spring Boot、Spring Data JPA (hibernate) Web 应用程序,并且想引入文本搜索功能。 我理解以下内容 hibernate search 或 spring
我不知道我的代码有什么问题。我读了其他有同样问题的人的一些问题,但没有找到答案。当我尝试编译时出现以下错误: ||In function 'main':| |35|error: expected ex
我不太确定为什么会收到此错误或其含义。我的数据框称为“数据”。 library(dplyr) data %>% filter(Info==1, Male==1) %>% lm(CFL_
我一直在 GitHub 等更现代的网站上看到这些属性,它们似乎总是与自定义的弹出窗口一致,如 title 属性。 Option 1 Option 2 Option 3 Option 4 我在 HTML
如何用 iCloud Core Data 替换我现有的 Core Data?这是我的持久商店协调员: lazy var persistentStoreCoordinator: NSPersistent
我一直在 GitHub 等更现代的网站上看到这些属性,它们似乎总是与自定义的弹出窗口一致,如 title 属性。 Option 1 Option 2 Option 3 Option 4 我在 HTML
我正在通过 this project 在 Android 上摆弄 node.js ,我需要一种方法将 js 文件部署到私有(private)目录(以隐藏源代码,防止用户篡改),该目录也物理存在于文件系
大家好我有点沮丧,所以我希望得到一些帮助。我的项目在 SwiftUI 中。我想使用图像选择器将图像保存到 Core Data。我实现了让 ImagePicker 工作,但我正在努力转换 Image -
我有以下数据和代码: mydf grp categ condition value 1 A X P 2 2 B X P 5
我一直在努力解决这个问题,但我根本找不到任何解决问题的方法。希望这里有人可以提供帮助。 我正在尝试为具有以下结构的某些数据创建个人选择矩阵: # A tibble: 2,152 x 32 a
我了解 Data.Map.Lazy 和 Data.Map.Strict 是不同的。但是,当您导入 Data.Map 时,您究竟导入了什么:严格的、惰性的还是两者的组合? 最佳答案 懒人。看着docs
我正在开发一个 C 程序,用于从 BerkeleyDB DBTree 数据库中提取数据值与特定模式匹配的记录。我创建数据库,打开它,将键的 DBT 和数据的另一个 DBT 清零,将 DBT 标志设置为
所以我有以下成员(member)历史表 User_ID | Start date | End Date | Type(0-7) | ---------------------------
随着最近推出的包dataframe ,我认为是时候正确地对各种数据结构进行基准测试,并突出每种数据结构的优势。我不是每个人的不同优势的专家,所以我的问题是,我们应该如何对它们进行基准测试。 我尝试过的
我有来自 API 的数据,但无法将数组中的数据设置为 vue.js 中的 this.data这是来自 API 的数据(JSON) 你能告诉我这个语法吗 {"id":1613, "name_org":"
在 Vue.js到目前为止,我已经找到了两种定义数据的方法:data: {} 和 data() { return; }. data: { defaultLayout: 'default' }
我正在研究Spring Data Rest Services,并在自定义拦截器中遇到一些问题。之前我使用spring-data-rest-webmvc 2.2.0并以以下方式添加了拦截器。 publi
我是一名优秀的程序员,十分优秀!