按照需求,需要在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完成智能提示的更多相关文章

  1. 五小步让VS Code支持AngularJS智能提示

    本文想通过配置VS Code来实现对AngularJS的智能提示.在一般的情况下对于在HTML页面是支持提示的.但是在js页面就不是很友好,它是记忆你之前的输入,要是之后有重复的输入,VS Code会 ...

  2. angular-ui-bootstrap typeahead 智能提示 自动补全 获取焦点不触发问题的解决

    项目中有一处使用了angular-ui-bootstrap中的typeahead来实现输入框智能提示语自动化补全的功能,存在一个bug, 即输入文字后,当再次点击文本框,其获取焦点后并不会触发智能提示 ...

  3. 在ASP.NET MVC中使用typeahead.js支持预先输入,即智能提示

    使用typeahead.js可以实现预先输入,即智能提示,本篇在ASP.NET MVC下实现.实现效果如下: 首先是有关城市的模型. public class City { public int Id ...

  4. Visual Studio Code 智能提示文件

    Visual Studio Code 开发前端和node智能提示 visual studio code 是一个很好的编辑器,可以用来编写前端代码和nodejs. 我很喜欢使用VSC,现在流行框架对VS ...

  5. VS2013中实现angular代码智能提示

    第一步:在项目同添加angular js文件的引用: 这里使用NuGet包管理器来给项目添加angular js install-package angularjs 第二步:添加智能提示js文件 我们 ...

  6. ExtJS ComboBox 录入智能提示

    ExtJS ComboBox非常复杂,有很多的属性:其中有的属性是针对某一种特定的方案而设计的,不是所有情况下都有效.我想下拉选择能支持录入,并且录入时能智能提示,弄了半天可以了,但是只能是mode= ...

  7. Eclipse代码和xml文件的智能提示

    一.代码智能提示 Windows → Preferences → Java→ Editor → Content Assist 将 Auto activation delay(ms): 改为 0 将 A ...

  8. Laravel 安装代码智能提示扩展「laravel-ide-helper」

    ========================laravel-ide-helper======================== 使用 Laravel 框架IDE居然没有智能提示?这感觉实在太糟糕 ...

  9. 利用typescript使backbone强类型智能提示

    模型类一旦多了没有强类型和智能提示是相当痛苦的,所以. 仅仅用ts定义一个模型类: class Person extends Backbone.Model { defaults = { Name:&q ...

随机推荐

  1. exit与_exit

    一.main函数: 先从程序的执行开始谈起,C程序总是从main函数开始执行,当内核执行C程序时(使用了一个exec函数),在调用main函数前先调用一个特殊的启动例程.可执行程序 文件将此启动例程指 ...

  2. 如何使用MacVim

    如何使用MacVim 如何使用MacVim 如何使用MacVim呢? 命令模式 按下ESC 高效率移动 1.在插入模式之外 基本上来说,你应该尽可能少的呆在插入模式里面,因为在插入模式里面 VIM 就 ...

  3. 2013集训.DAY21.A

    随便点了一套刷,这套质量挺棒的,学了不少的东西,并且碰到了很久都没有打的题目 T1 card [指针技巧] 题1 集卡片 [问题描述] lzh小时候很喜欢收集卡片,他经常要去商店购买新到的卡片. 商店 ...

  4. CC/G++ 学习笔记

    CC/G++ 学习笔记 本文是<An introduction to GCC>的学习笔记,记录使用GCC/G++主要的实用技巧,本文讲述的知识基本上摘自本书,附带自己的一些体验.如果想详细 ...

  5. AE基础知识之地图浏览

    地图浏览:(放大缩小平移全图) //全局变量 public enum enumToolFlag { None ZoomOut, ZoomIn, Pan, } enumToolFlag flag = e ...

  6. 验证码生成组件--JCaptcha的使用

    以下为项目中所用代码,文笔有限,直接上代码. 所需jar包: 是否需要其他依赖包,不详 web.xml <servlet> <servlet-name>Jcaptcha< ...

  7. 使用Guava进行函数式编程

    本文翻译自Getting Started with Google Guava这本书,如有翻译不足的地方请指出. 在这一章,我们开始注意到使用Guava进行编写代码会更加简单.我们将看看如何使用Guav ...

  8. 在windows上编译MatConvNet

    有个BT的要求,在windows上使用MatConvNet,并且需要支持GPU. 费了些力气,记录一下过程(暂不支持vl_imreadjpeg函数) 在这里下载MatConvNet,机器配置vs201 ...

  9. node.js系列笔记之fs模块《二》

    一:感触 最近工作比较忙,感觉也比较多,因为工作上的不顺利,再加上加班比较多,所以最近心情不是很好,再加上英语能力差到不行,所以最近半个月学习进度也比较慢, 但还是告诉自己每天都坚持学一点,即使今天心 ...

  10. SQL拼接方法

    smark Beetle可靠.高性能的.Net Socket Tcp通讯组件 另类SQL拼接方法 在编写SQL的时候经常需要对SQL进行拼接,拼接的方式就是直接String+处理,但这种情况有个不好的 ...