我有以下代码使用Typeahead.js作为建议.我没有关于代码的重大问题,因为它工作正常.
我面临的一个小问题是,在任何给定时间内,即使远程URL中有超过5条建议,我也只看到5条建议.
var isearch = new Bloodhound({
datumTokenizer: function(d) {
return Bloodhound.tokenizers.whitespace(d.value);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: "http://localhost/search/get-data/%QUERY"
});
isearch.initialize();
$("#search_box .typeahead").typeahead(null,{ name: "isearch",
displayKey: "value",
source: isearch.ttAdapter(),
templates: {
suggestion: Handlebars.compile("{{value}}")
}
});
Run Code Online (Sandbox Code Playgroud)
我的期望是有更多的建议,应该有一个滚动条供用户查看.
setState()方法应该被称为的内部initState()方法StatefullWidget吗?
我的理解是该initState()方法将自动应用状态。
下面的代码不起作用。post对象的值为空。
@override
void initState() {
ItemService.getItemById(widget.postId).then((DocumentSnapshot doc){
post = ItemService.getPostFromDocument(doc);
});
}
Run Code Online (Sandbox Code Playgroud)
但是下面的作品。
@override
void initState() {
ItemService.getItemById(widget.postId).then((DocumentSnapshot doc){
setState((){
post = ItemService.getPostFromDocument(doc);
});
});
}
Run Code Online (Sandbox Code Playgroud)
在其他一些情况下,即使不使用setState()同一类也可以正常工作。
因此,什么时候应该使用setState()内部initState()方法,什么时候不应该使用?
另一个相关问题:
super.initState()我initState()什么时候应该打电话给我?我不打扰没关系吗?
我在动态页面中使用intro.js,如果提供的所有元素都存在,那么巡演就没有任何问题了.
但是如果任何元素不存在,则动态生成页面,游览停止并且必须按下NEXT按钮两次以继续进行.
如果元素不存在,有没有办法完全跳过这个步骤?
例:
intro.setOptions({
steps[
{"element":".ow_status","intro":"status"},
{"element":".ow_mailbox","intro":"mailbox"},
{"element":".ow_test","intro":"test"}
]
});
Run Code Online (Sandbox Code Playgroud)
在上面的示例中,如果不存在类ow_mailbox的元素,则游览将在中间停止并显示3个步骤,尽管只有2个具有有效元素.
我正在使用多个远程数据集来获取Typeahead插件的数据.一切正常.
现在我正在努力实现两件事
如果所有远程数据集都未获取任何结果,则应显示"未找到结果".如果任何1个远程源有数据,则不应显示此信息.
如果有结果,我想在typeahead容器的页脚显示一个静态链接.如何在页脚显示链接?
我怎样才能做到这一点?我不知道该怎么办.
有一些示例显示每个部分的页脚,而不是使用"空"和"页脚"类的整个容器.但它们在数据集级别而不是全局.
链接:https://github.com/twitter/typeahead.js/blob/master/doc/jquery_typeahead.md#datasets
与此类似的其他SO问题:
var nbaTeams = new Bloodhound({
datumTokenizer: function(d) { return Bloodhound.tokenizers.whitespace(d.value); },
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: '../data/nba.json'
});
var nhlTeams = new Bloodhound({
datumTokenizer: function(d) { return Bloodhound.tokenizers.whitespace(d.value); },
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: '../data/nhl.json'
});
nbaTeams.initialize();
nhlTeams.initialize();
$('#multiple-datasets .typeahead').typeahead({
highlight: true
},
{
name: 'nba-teams',
displayKey: 'team',
source: nbaTeams.ttAdapter(),
templates: {
header: '<h3 class="league-name">NBA Teams</h3>'
}
},
{
name: 'nhl-teams',
displayKey: 'team',
source: nhlTeams.ttAdapter(),
templates: {
header: '<h3 class="league-name">NHL Teams</h3>'
} …Run Code Online (Sandbox Code Playgroud) 我正在使用Ionic框架来构建混合Android应用程序,该应用程序运行正常.我正在使用Fabric Crash analytics插件并报告应用程序的崩溃.
我经常收到下面的崩溃细节,不知道是什么原因.我不确定开始分析这个的起点是什么.
Fatal Exception: java.lang.NullPointerException
at android.webkit.WebViewClassic.setNetworkAvailable(WebViewClassic.java:4224)
at android.webkit.WebView.setNetworkAvailable(WebView.java:731)
at org.apache.cordova.engine.SystemWebViewEngine$1.setNetworkAvailable(SystemWebViewEngine.java:112)
at org.apache.cordova.NativeToJsMessageQueue$OnlineEventsBridgeMode$2.run(NativeToJsMessageQueue.java:340)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5319)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(NativeStart.java)
Run Code Online (Sandbox Code Playgroud)
它与Ionic或Cordvoa中的任何插件或任何问题有关吗?任何帮助或建议都会有所帮助.
我正在使用下面的代码在网格中显示卡片,它工作正常。
return new GridView.count(
primary: false,
padding: const EdgeInsets.all(1.5),
crossAxisCount: 2,
childAspectRatio: 0.80,
mainAxisSpacing: 1.0,
crossAxisSpacing: 1.0,
children: _loadCategories(), //new Cards()
shrinkWrap: true,
);
Run Code Online (Sandbox Code Playgroud)
目前横向和纵向显示如下。
但我希望所有网格/卡片(在本例中为 6 个)完全填充视图端口。所有 6 张卡片都应在视口中可见。目前,最后 2 张卡在纵向模式下位于视口下方,在横向模式下有 4 张卡位于视口下方。
如何让所有卡片根据屏幕尺寸重塑?
只是好奇下面的内容:
是否可以使网格响应而不是在一行中固定项目?
EIDT 1:
我使用下面的卡片 6 次来生成以下内容。
List<Widget> _loadCategories() {
List<Widget> categoryCells = [];
List<CategoryItem> categories = new CategoryManager().categories();
for (CategoryItem category in categories) {
categoryCells.add(getStructuredGridCell(category));
}
return categoryCells;
}
Card getStructuredGridCell(CategoryItem item) {
return new Card(
elevation: 2.0,
color: item.color,
child: new InkWell(
highlightColor: …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Android平台中的Phonegap/Cordova构建混合移动应用程序.而且我也成功了:)该应用程序在我的Chrome浏览器中按照Ripple模拟器的需要运行.我没有使用Eclipe ADT或Android Studio,因为模拟器无法快速加载.
我使用onDeviceReady事件和Navigator插件进行振动和警报.所有这些都按预期正常工作.
当开发者控制台在Chrome中处于活动状态时,JavaScript会在cordova.js中断,并显示以下错误
Uncaught ReferenceError: require is not defined
Run Code Online (Sandbox Code Playgroud)
在以下行中.对于notification.js文件也是如此.当我在调试器中按下continue时,除了该错误之外,所有内容都会按预期再次运行.
var cordova_events = require('./src/events'),
Run Code Online (Sandbox Code Playgroud)
java脚本文件的顺序如下所示.
<script src="js/cordova.js"></script>
<script src="js/notification.js"></script>
<script src="js/vibration.js"></script>
Run Code Online (Sandbox Code Playgroud)
我相信我没有引用正确的cordova.js文件和所有其他依赖项.但我也想知道当开发者控制台不活动时,应用程序如何在Ripple中正常工作.
我甚至尝试删除cordova.js文件,因为Ripple会根据phonegap deviceready事件自动包含它- 波纹模拟器
我有各自网站的phonegap和cordova的下载副本.我已经安装了Node.js并安装了软件包.
我的问题是:
我承认node.js的概念和用法对我来说看起来像火箭科学.
我在HTML表单中使用Select2 jQuery插件通过ajax调用获取远程数据.此功能正常.
但是,在提交表单时,Select2元素中的选定值在POST数据中不可用.
我能够获取有关单选按钮和提交按钮的数据,但不能获取与Select2绑定的userbox元素.
如何在表单中获取所选数据以便在PHP中进行处理?
<form name='adminForm' method="post">
<input type="radio" name="type" value="all"> 1 <br/>
<input type="radio" name="type" value="from"> 2 <br/>
<input type="radio" name="type" value="to"> 3 <br/>
<div id="userbox"></div>
<input type="submit" value="Submit" name="searchMessages">
</form>
Run Code Online (Sandbox Code Playgroud)
下面是我使用的jQuery代码.
$("#userbox").select2({
minimumInputLength: 1,
formatResult: productFormatResult, // Not provided here
formatSelection: productFormatSelection, // Not provided here
ajax: {
url: "/url/path",
data: function (term, page) {
return {
q: term,
};
},
results: function (data, page) {
return {results: data};
}
},
escapeMarkup: function (m) { return m; …Run Code Online (Sandbox Code Playgroud) 我有一个包含 2 个字段的云 FireStore 数据库。
以下是我从图像集合中获取文档的方法。
class ImagePost {
final String imageUrl;
final User user;
const ImagePost(
{this.imageUrl,
this.user});
factory ImagePost.fromDocument(DocumentSnapshot document) {
User userInfo;
DocumentReference userReference = document['user'];
Future<DocumentSnapshot> userRef = userReference.get();
userRef.then((document) {
userInfo = User.fromJSON(document.data);
});
ImagePost post = new ImagePost(
imageUrl: document['imageUrl'],
user: userInfo // ==> always null while returning
);
return post;
}
}
Run Code Online (Sandbox Code Playgroud)
获取引用用户文档时,post对象始终包含用户字段的空值。我希望填充用户对象。
但是用户值被延迟检索并且没有与 post 对象一起返回。
如何确保在返回帖子值之前检索用户值?
我正在尝试创建一个接受类作为参数并执行一些操作并返回相同类的列表的方法.
我正在尝试使用泛型并具有以下代码.
问题: 如何将提供的类映射到BeanListProcessor类型和List?
注意:此代码不正确,将产生语法错误.这是一种解释我的要求的模板.
public static List<?> process(Class<?> bean) {
List<?> rows = new ArrayList<>();
BeanListProcessor<bean> processor = new BeanListProcessor<bean>(bean.getClass());
....
return rows;
}
Run Code Online (Sandbox Code Playgroud)