我有一个可以自行路由但具有不同路由参数的组件。
您可能知道这不会触发constructor或ngOnInit。
为了解决这个问题,我在构造函数中添加了以下内容
this.router.routeReuseStrategy.shouldReuseRoute = function () {
return false;
}
Run Code Online (Sandbox Code Playgroud)
这解决了问题,但是我意识到我的路线在使用时会发疯。例如,指向完全不同的路由的链接变为活动状态,当我将鼠标悬停在该链接上时,它似乎已从url更改为当前URL。(难以描述)
我正在尝试 angular,我有一个显示国家/地区列表的主页组件,我想在详细信息视图中显示有关该国家/地区的更多信息。
当我将数据通过管道传输到模板中的 json 时,我实际上可以看到数据,但无法访问对象的属性。
在 home.html 我有
<ion-list>
<ion-item *ngFor="let country of countries">
<ion-avatar item-start>
<img [src]="country.flag" />
</ion-avatar>
<h5>{{country.name}}</h5>
<p>{{country.exchange_count}} Exchanges</p>
<button ion-button primary outline item-end (click)="about(country)">View</button>
</ion-item>
</ion-list>
Run Code Online (Sandbox Code Playgroud)
家.ts
about(country){
console.log(typeof(country))
this.navCtrl.push(AboutPage, {country:country})
}
Run Code Online (Sandbox Code Playgroud)
about.ts,控制台打印国家名称
ionViewDidLoad () {
this.country = this.navParams.get('country');
console.log(this.country.name);
}
Run Code Online (Sandbox Code Playgroud)
about.hmtl,这里是执行类似country.name引发错误的操作的地方,can't access property name of undefined但是当我按如下操作时,转储的数据会显示在页面上。
<ion-content>
{{country | json}}
<!-- {{country.name}} -->
</ion-content>
Run Code Online (Sandbox Code Playgroud)
在 about.html 页面上,这是通过管道传输到 json 时的结果,为了简洁起见,我修剪了数据
{"id":"1","name":"Ghana","iso_code":"GHS","currency":"GHS",
"exchange_count":1}
Run Code Online (Sandbox Code Playgroud)
我已经尝试了几件事,我错过了什么?
我不是设计师,但是当我得到这个项目时,我不能打开一些屏幕,我认为它们是屏幕,我们只重用了一些已经创建的布局.无论如何可以有人帮助我吗?@Override public void onBindViewHolder(@NonNull final ProductsAdapter.ViewHolder holder,final int position){String imageUrl = ProductsList.get(position).getImage();
holder.itemName.setText(ProductsList.get(position).getName());
Picasso.with(context).load(imageUrl).into(holder.itemImage);
holder.parentLayot.setOnClickListener(new View.OnClickListener() {
public String currentActivity;
@Override
public void onClick(View v) {
Activity activity = (Activity) v.getContext();
activity.runOnUiThread(bd);
String activityName = activity.getClass().getSimpleName();
// Toast.makeText(activity,ProductsList.get(position).getId(),Toast.LENGTH_SHORT).show();
if (activityName.equals("Product_View")){
// Toast.makeText(activity,"Click and pass",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(activity, Second_Product_View.class);
intent.putExtra("item_name", ProductsList.get(position).getName());
intent.putExtra("item_id", ProductsList.get(position).getId());
intent.putExtra("item_category_name", ProductsList.get(position).getName());
intent.putExtra("item_category_id", ProductsList.get(position).getId());
activity.startActivity(intent);
} else if(activityName.equals("Second_Product_View")){
Intent intent = new Intent(activity, Third_Product_View.class);
intent.putExtra("item_category_name", activity.getIntent().getStringExtra("item_category_name"));
intent.putExtra("item_category_id", activity.getIntent().getStringExtra("item_category_id"));
intent.putExtra("item_subcategory_name", ProductsList.get(position).getName());
intent.putExtra("item_subcategory_id", ProductsList.get(position).getId());
intent.putExtra("item_name", ProductsList.get(position).getName());
intent.putExtra("item_id", ProductsList.get(position).getId()); …Run Code Online (Sandbox Code Playgroud) 我在一个类中有这个状态对象:
state = {
ingredients: {
salad: 1,
bacon: 5,
cheese: 2,
meat: 2
}
}
Run Code Online (Sandbox Code Playgroud)
并希望将其转换为一个数组,该数组也获取值编号,如下所示:
const burger = (props) => {
const transformedIngredients = Object.keys(props.ingredients)
.map(igKey => {
return [...Array(props.ingredients[igKey])].map((_,i)=>{
return <BurgerIngredient key={igKey + i} type={igKey}/>
});
});
console.log(transformedIngredients)
return(
<div className={classes.Burger}>
<BurgerIngredient type="bread-top" />
<BurgerIngredient type="cheese" />
<BurgerIngredient type="meat" />
<BurgerIngredient type="bread-bottom" />
</div>
);
};
export default burger;
Run Code Online (Sandbox Code Playgroud)
我按照教程成功地做到了,老实说我不完全理解这里发生了什么。特别是这部分:
return [...Array(props.ingredients[igKey])].map((_,i)=>{
return <BurgerIngredient key={igKey + i} type={igKey}/>
});
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激!谢谢!
const arr = ['be-', 'fe-', 'automated'];
const str = 'fe-cheese';
const oi = arr.includes(str) ? 'cheese' : 'meat';
console.log(oi);
Run Code Online (Sandbox Code Playgroud)
我有一个部分匹配的数组,我想检查字符串是否包含任何部分arr.
meat当它匹配fe-并返回时,上面返回cheese
我最近发现了这样的JavaScript代码:
someFunction()()
在没有经典IIFE语法的函数之后立即调用函数.
这种语法叫做什么?它是如何工作的?