我想在android上每隔x分钟运行一次fetch(使用React native)
function getMoviesFromApiAsync() {
return fetch('https://facebook.github.io/react-native/movies.json').then((response) => response.json()) .then((responseJson) => {
return responseJson.movies; }) .catch((error) => { console.error(error); });
}
Run Code Online (Sandbox Code Playgroud)
我开始使用documentaion中的示例,因为我还不确定如何进行此类提取.
我不知道我应该怎么开始这个(做一个Android本机处理程序可能?).我只找到了一个组件,但这是用于ios iOS后台获取API实现
我在HorizontalScrollView中使用LinearLayout滚动部分正在工作,但我无法弄清楚如何制作3行.
例如:
粗体显示当前显示的内容(在模拟器/屏幕上)
当前
--Button1 -将Button2 - Button3--将Button4 - Button5 - Button6 - Button7 -按钮8 -按钮9 - Button10
-Button11 - Button12
我想要的是
--Button1 -将Button2 - Button3--将Button4 - Button5 - Button6--
--Button7 -按钮8 - Button9-- Button10 - Button11 - Button12--
我正在尝试使用一个LinearView,因为稍后我会尝试动态添加按钮.
我可能会以完全错误的方式做这件事(我想我是).
这是代码:
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp" >
<LinearLayout
android:layout_width="200dp"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button2" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button3" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button4" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button5" /> …Run Code Online (Sandbox Code Playgroud) 我是正则表达式的新手,但是在StackOverflow上进行了一些搜索,我设法得到了我想要的东西(如果2个单词被逗号分隔,那么它返回true并返回false,如果不是这样或单词结束除了我有克罗地亚字符(č,ć,ž,đ,š大写和小写)的问题之外,用逗号但后面没有任何内容.我目前的preg_match样子
if (preg_match('/^(([a-zA-Z0-9]+\\s*,\\s*)+(\\s*)([a-zA-Z0-9]+))$/', $data))
{
//do stuff
}
Run Code Online (Sandbox Code Playgroud)
但是,这种方法的问题是,如果有也不会返回true ?,?,ž...我知道那是因为[a-zA-Z]不"看"这个字.所以,我的问题是如何编写一个将使用克罗地亚字符返回true的正则表达式.如果可以做到这一点,也可以随意发表评论,因为我想听听你的建议.顺便说一句,我是在regex101.com的帮助下完成的
我想限制相关记录来自
$categories = Category::with('exams')->get();
Run Code Online (Sandbox Code Playgroud)
这将使我获得所有类别的考试,但我想要的是从一个类别和每个类别获得 5 个考试。
类别模型
public function Exams() {
return $this->hasMany('Exam');
}
Run Code Online (Sandbox Code Playgroud)
考试模式
public function category () {
return $this->belongsTo('Category');
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试了几件事,但无法让它工作
首先我发现的是这样的
$categories = Category::with(['exams' => function($exams){
$exams->limit(5);
}])->get();
Run Code Online (Sandbox Code Playgroud)
但问题是它只会让我从所有类别中获得 5 条记录。我也尝试为类别模型添加限制
public function Exams() {
return $this->hasMany('Exam')->limit(5);
}
Run Code Online (Sandbox Code Playgroud)
但这并没有做任何事情,并且返回艰难,它没有限制 5。
那么有没有一种方法可以用 Eloquent 来做到这一点,或者我应该简单地加载所有东西(想传递它)并使用 foreach 的 break 吗?
是否可以检查脚本是否使用 Javascript 打开了一个窗口?
我有用户协议,它们在新窗口中打开,这有效(当我尝试关闭窗口时)
<a href="JavaScript:window.close()" class="btn btn-default">Return</a>
Run Code Online (Sandbox Code Playgroud)
但我想要完成的是,如果用户直接转到/agreeement并单击关闭,它将他重定向到主页。因为现在如果我这样做,我会收到一条消息
脚本可能只关闭由它打开的窗口。
我明白为什么。这就是为什么我想检查窗口是否未从脚本重定向到 index.html 的位置打开的原因。但我不知道我将如何进行检查
我已经像这样添加了Map to Fragment
public class SomeFragment extends Fragment {
MapView mapView;
GoogleMap map;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.some_layout, container, false);
// Gets the MapView from the XML layout and creates it
mapView = (MapView) v.findViewById(R.id.mapview);
mapView.onCreate(savedInstanceState);
// Gets to GoogleMap from the MapView and does initialization stuff
map = mapView.getMap();
map.getUiSettings().setMyLocationButtonEnabled(false);
map.setMyLocationEnabled(true);
// Needs to call MapsInitializer before doing any CameraUpdateFactory calls
try {
MapsInitializer.initialize(this.getActivity());
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace(); …Run Code Online (Sandbox Code Playgroud) 我希望我的第二个数组按id第一个数组中的属性排序。
这是我的数组
第一个数组
data :
items:
0: {id: 14, attributes: Array(1)}
1: {id: 8, attributes: Array(1)}
2: {id: 4, attributes: Array(1)}
3: {id: 1, attributes: Array(2)}
4: {id: 2045, attributes: Array(2)}
Run Code Online (Sandbox Code Playgroud)
第二个数组
data :
items:
0: {id: 1, name: "test Product 1"}
1: {id: 4, name: "test Product 1"}
2: {id: 8, name: "test Product 1"}
3: {id: 14, name: "test Product 1"}
4: {id: 2045, name: "test Product 1"}
Run Code Online (Sandbox Code Playgroud)
我是这样试的:
但我似乎无法让它工作。我知道这被问了很多,但我就是想不通。
这是我的模板
<div *ngIf="attachments">
<div>
{{ 'attachments' | translate }}
</div>
{{ attachments.data[0].title }} <!-- this works -->
<div *ngFor="let item of attachments.data"> <!-- this doesn't -->
<a [href]="item.href">{{ item.title }}</a>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
现在,当我像这样attachments.data[0].title在上面打印标题时,它会显示,但是当我尝试迭代时,attachments.data它不会显示
抱歉不是我写的。它不显示任何错误,只是不呈现
android ×3
javascript ×2
angular ×1
eloquent ×1
google-maps ×1
laravel ×1
laravel-4 ×1
lodash ×1
memory-leaks ×1
one-to-many ×1
php ×1
regex ×1
sql-limit ×1