在查询数组中的数组时,我有点迷失。我的模型包括以下内容:
(安排)> (InterestedPlayers,JustPlayId)> (姓名,身份证)
在代码中我有按钮在这个foreach循环中触发模式:
node.d.ts
现在我想列出感兴趣的玩家的名字,每个名字都有一个复选框。 所以我尝试了这个表达式:
foreach (var item in Model.Arrangements)
{
...
}
有什么建议吗?
答案 0 :(得分:0)
public boolean launchCamera(View view) {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
File photo;
try {
// place where to store camera taken picture
photo = this.createTemporaryFile("picture", ".jpg");
photo.delete();
} catch (Exception e) {
Log.v(TAG, "Can't create file to take picture!");
Toast.makeText(MainActivity.this, "Please check SD card! Image shot is impossible!", Toast.LENGTH_LONG);
return false;
}
mImageUri = Uri.fromFile(photo);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri);
//start camera intent
this.startActivityForResult(intent, MenuShootImage);
return true;
}
private File createTemporaryFile(String part, String ext) throws Exception {
File tempDir = Environment.getExternalStorageDirectory();
tempDir = new File(tempDir.getAbsolutePath() + "/.temp/");
if (!tempDir.exists()) {
tempDir.mkdir();
}
return File.createTempFile(part, ext, tempDir);
}
public Bitmap grabImage()
{
this.getContentResolver().notifyChange(mImageUri, null);
ContentResolver cr = this.getContentResolver();
Bitmap bitmap=null;
try
{
bitmap = android.provider.MediaStore.Images.Media.getBitmap(cr, mImageUri);
}
catch (Exception e)
{
Toast.makeText(this, "Failed to load", Toast.LENGTH_SHORT).show();
Log.d(TAG, "Failed to load", e);
}
return bitmap;
}
public void onActivityResult(int requestCode, int resultCode, Intent intent)
{
Intent imagepass = null;
Bitmap bitmap = null;
if(requestCode == MenuShootImage && resultCode == RESULT_OK)
{
bitmap = this.grabImage();
imagepass = new Intent(this,MainActivity2.class);
imagepass.putExtra("imagepass", bitmap );
startActivity(imagepass);
}
}
并使用jquery获取感兴趣的玩家的所有选择名称
答案 1 :(得分:0)
Html.CheckBoxFor需要绑定bool属性,而不是像Name这样的字符串属性。您应该在模型中创建一个bool属性,如IsSelect。
(安排)> (InterestedPlayers,JustPlayId)> (姓名,身份证)
InterestedPlayers =>名称(字符串),IsSelect(bool)
例如,试试这个:
int i = 0, j = 0;
foreach (var item in Model.Arrangements)
{
foreach(var player in item.InterestedPlayers)
{
Html.CheckBoxFor(m => m.Arrangements[i].InterestedPlayers[j].IsSelect)
Html.LabelFor(m => m.Arrangements[i].InterestedPlayers[j].Name)
j++;
}
j = 0;
i++;
}
答案 2 :(得分:0)
上面已经发布了一些很好的解决方案,但我认为我会在此期间发布我想出的内容,而不是使用html.checkbox。
@using (Html.BeginForm("MoveToOverFlow", "JustPlay", new {id = Model.Id, slug = Model.Slug}))
{
foreach (var player in item.InterestedPlayers)
{
@player.Name
@Html.CheckBox("PlayerId", new { value = player.Id})
@Html.SubmitButton(">>>>>>",true,new {@class = "btn btn-primary"})
}
}
这会将一个列表发送回控制器,如果选中此复选框,则该列表具有播放器的ID,如果未选中则为“false”