AngularJs facebook喜欢提到:如何在没有触发器字符的情况下开始提及建议,例如: ' @'

时间:2016-12-23 07:04:55

标签: javascript jquery angularjs ment.io

我正在使用第三方库 mento.io Github来满足我的要求。

这个库足以在特定字符后显示建议,但我的要求是用户在某些编辑器上开始像IntelliSense一样输入时应该得到建议。

问题

如何在用户点击任何字符时启动建议。现在它只使用@符号



// Code goes here


var app = angular.module('app', ['mentio']);

app.controller('ctrl', function ($scope) {

    $scope.people = [
        { label: 'Joe' },
        { label: 'Mike' },
        { label: 'Diane' }
    ]

    $scope.myval = '';
});

<!DOCTYPE html>
<html>

  <head>
    
    
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>


	<!-- Latest compiled and minified CSS -->
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
		crossorigin="anonymous">

	<!-- Optional theme -->
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp"
		crossorigin="anonymous">

	<!-- Latest compiled and minified JavaScript -->
	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
		crossorigin="anonymous"></script>
	<!--<link rel="stylesheet" href="style.css" />-->

	<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
	<script src="https://jeff-collins.github.io/ment.io/dist/mentio.js"></script>
	
	
    <script src="script.js"></script>
  </head>

  <body><div ng-app="app" ng-controller='ctrl'>

		<input type="text" mentio id="test" mentio-id="'test'" mentio-typed-text="typedTerm" mentio-trigger-char="'@'" mentio-items="people"
			ng-model="myval" />
	</div>
  </body>

</html>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

如果您需要使用mentio.io lib来解决这个问题,请查看此拉取请求:

https://github.com/jeff-collins/ment.io/pull/94

我使用mento.io遇到了同样的问题,刚刚更改了框架:https://leaverou.github.io/awesomplete

答案 1 :(得分:0)

mentio-trigger-char="''"似乎有效,对我来说似乎有些尴尬,但它有效

// Code goes here


var app = angular.module('app', ['mentio']);

app.controller('ctrl', function ($scope) {

    $scope.people = [
        { label: 'Joe' },
        { label: 'Mike' },
        { label: 'Diane' }
    ]

    $scope.myval = '';
});
<!DOCTYPE html>
<html>

  <head>
    
    
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>


	<!-- Latest compiled and minified CSS -->
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
		crossorigin="anonymous">

	<!-- Optional theme -->
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp"
		crossorigin="anonymous">

	<!-- Latest compiled and minified JavaScript -->
	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
		crossorigin="anonymous"></script>
	<!--<link rel="stylesheet" href="style.css" />-->

	<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
	<script src="https://jeff-collins.github.io/ment.io/dist/mentio.js"></script>
	
	
    <script src="script.js"></script>
  </head>

  <body><div ng-app="app" ng-controller='ctrl'>

		<input type="text" mentio id="test" mentio-id="'test'" mentio-typed-text="typedTerm" mentio-trigger-char="''" mentio-items="people"
			ng-model="myval" />
	</div>
  </body>

</html>