angularjs-xeditable整合typeahead完成智能提示
按照需求,需要在angularjs的xeditable中加入typeahead,来完成智能提示,并且在选择后,把该条数据的其他信息也显示在此行中,于是做了一下的测试修改。
当然,既然用了xeditable肯定就需要加入这个模块。
var Myapp = angular.module('Myapp ',['xeditable']);
下面是页面上的html代码
<div ng-controller="productController">
<table class="table table-bordered table-condensed">
<tr style="font-weight: bold">
<td style="width:10%">类型</td>
<td style="width:20%">名称</td> <td style="width:25%">Edit</td>
</tr>
<tr ng-repeat="product in products">
<td>
<span editable-text="product.type" e-name="type" e-form="rowform"
e-uib-typeahead="products.type for products in products | filter:$viewValue | limitTo:8"
e-typeahead-on-select="getProductDetail($item, $model)"
>
{{ product.type || 'empty' }}
</span>
</td>
<td>
<span editable-text="product.name" e-name="name" e-form="rowform" >
{{ product.name || 'empty' }}
</span>
</td> <td style="white-space: nowrap">
<form editable-form name="rowform" onbeforesave="saveProduct($data,product.id)" ng-show="rowform.$visible" class="form-buttons form-inline" shown="inserted == product">
<button type="submit" ng-disabled="rowform.$waiting" class="btn btn-primary">
save
</button>
<button type="button" ng-disabled="rowform.$waiting" ng-click="rowform.$cancel()" class="btn btn-default">
cancel
</button>
</form>
<div class="buttons" ng-show="!rowform.$visible">
<button class="btn btn-primary" ng-click="rowform.$show()">edit</button>
<button class="btn btn-danger" ng-click="removeProduct($index,product)">del</button>
</div>
</td>
</tr>
</table>
<button class="btn btn-default" ng-click="addProduc()">Add row</button>
</div>
Js代码
//因为暂时未能解决$http的同步问题,所以只能取出所有数据,然后在匹配
$http.get("selectAllProduct")
.success(function(data){
$scope.products=data;
})
/*var xmlHttp;
此方法虽然能实现,但是页面数据有问题
使用原生的XMLHttpRequest同步获取数据
function createXMLHttpRequest(){
if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}else if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
$scope.getProducts=function(type){
createXMLHttpRequest();
if(xmlHttp!=null){
xmlHttp.open("GET","selectProductByType/"+type,false);
xmlHttp.send(null);
}
console.log(xmlHttp.responseText);
return xmlHttp.responseText; }*/
//获取产品详细信息
$scope.getProductDetail = function ($item, $model) {
$scope.inserted = {
type: $model
name: $item.name,
}
$scope.products[$scope.products.length-1]=$scope.inserted;
};
//保存产品
$scope.saveProduct= function(data,id) {
angular.extend(data, {id: id});
return $http.post('saveProduct', data);
};
//添加行
$scope.addProduct = function() { $scope.inserted = {
type: '',
name:''
};
$scope.esms.push($scope.inserted);
}
//删除行
$scope.removeProduct = function(index,product) {
if (confirm("你确定删除此行?")){
$http.get("delete"+product.id)
.success(function(data){
$scope.products.splice(index, 1);
})
}
};
小结:
关于如何使用$http完成同步获取数据的问题目前暂时未能解决
angularjs-xeditable整合typeahead完成智能提示的更多相关文章
- 五小步让VS Code支持AngularJS智能提示
本文想通过配置VS Code来实现对AngularJS的智能提示.在一般的情况下对于在HTML页面是支持提示的.但是在js页面就不是很友好,它是记忆你之前的输入,要是之后有重复的输入,VS Code会 ...
- angular-ui-bootstrap typeahead 智能提示 自动补全 获取焦点不触发问题的解决
项目中有一处使用了angular-ui-bootstrap中的typeahead来实现输入框智能提示语自动化补全的功能,存在一个bug, 即输入文字后,当再次点击文本框,其获取焦点后并不会触发智能提示 ...
- 在ASP.NET MVC中使用typeahead.js支持预先输入,即智能提示
使用typeahead.js可以实现预先输入,即智能提示,本篇在ASP.NET MVC下实现.实现效果如下: 首先是有关城市的模型. public class City { public int Id ...
- Visual Studio Code 智能提示文件
Visual Studio Code 开发前端和node智能提示 visual studio code 是一个很好的编辑器,可以用来编写前端代码和nodejs. 我很喜欢使用VSC,现在流行框架对VS ...
- VS2013中实现angular代码智能提示
第一步:在项目同添加angular js文件的引用: 这里使用NuGet包管理器来给项目添加angular js install-package angularjs 第二步:添加智能提示js文件 我们 ...
- ExtJS ComboBox 录入智能提示
ExtJS ComboBox非常复杂,有很多的属性:其中有的属性是针对某一种特定的方案而设计的,不是所有情况下都有效.我想下拉选择能支持录入,并且录入时能智能提示,弄了半天可以了,但是只能是mode= ...
- Eclipse代码和xml文件的智能提示
一.代码智能提示 Windows → Preferences → Java→ Editor → Content Assist 将 Auto activation delay(ms): 改为 0 将 A ...
- Laravel 安装代码智能提示扩展「laravel-ide-helper」
========================laravel-ide-helper======================== 使用 Laravel 框架IDE居然没有智能提示?这感觉实在太糟糕 ...
- 利用typescript使backbone强类型智能提示
模型类一旦多了没有强类型和智能提示是相当痛苦的,所以. 仅仅用ts定义一个模型类: class Person extends Backbone.Model { defaults = { Name:&q ...
随机推荐
- C#对文件的操作
本文收集了目前最为常用的C#经典操作文件的方法,具体内容如下:C#追加.拷贝.删除.移动文件.创建目录.递归删除文件夹及文件.指定文件夹下 面的所有内容copy到目标文件夹下面.指定文件夹下面的所有内 ...
- Redis一些命令总结
链接操作相关的命令 quit:关闭连接(connection) auth:简单密码认证 持久化 save:将数据同步保存到磁盘 bgsave:将数据异步保存到磁盘 lastsave:返回上次成功将 ...
- [转]Data Structure Recovery using PIN and PyGraphviz
Source:http://v0ids3curity.blogspot.com/2015/04/data-structure-recovery-using-pin-and.html --------- ...
- Area 使用
[ASP.NET MVC 小牛之路]08 - Area 使用 ASP.NET MVC允许使用 Area(区域)来组织Web应用程序,每个Area代表应用程序的不同功能模块.这对于大的工程非常有用,Ar ...
- .NET PageAdmin CMS
.NET PageAdmin CMS 完全破解步骤(非简单去版权) 其实当初我的目的是很纯洁的,只是想找一个简单的网站生成模板,由于对.net更熟悉一点,就去搜索了.net框架的CMS,看它的介绍挺强 ...
- jQuery幻灯片插件Skippr
Skippr是一款带左右箭头,索引按钮,滑动切换效果并且轻量.快速的幻灯片 设置 引入jquery.skippr.css.jquery.js.jquery.skippr.js 注意jQuery必须在j ...
- JS错误:Uncaught SyntaxError: Unexpected token ILLEGAL
$('tbody', '#' + tableId).append('<tr onmouseover="this.style.backgroundColor=\'#eeeeee\'&qu ...
- eclipse plugin 导出插件包
当我们的插件在完成一个阶段性开发的时候,我们要发布一个1.0的版本.这个时候会碰到一个问题.如何把我们的插件打成包?有多种途径,下面具体讨论一下. 首先从插件完成到被他人(或者我们自己)使用有两个步骤 ...
- C/C++单链表
C/C++单链表 先看例子,例1:定义链表 //定义链表 struct stu { int name; int age; struct stu *next; }; 用一组地址任意的存储单元存放线性表中 ...
- Android 点击桌面快捷方式和Notifycation跳转到Task栈顶Activity
我们一般下载的应用在第一次启动应用的时候都会给我创建一个桌面快捷方式,然后我在网上找了些资料整理下了,写了一个快捷方式的工具类,这样我们以后要创建快捷方式的时候直接拷贝这个类,里面提供了一些静态方法, ...