public class MyViewModel : MvxViewModel
{
public bool MenuItemIsEnabled {
get{return _menuItemIsEnabled;}
set{SetProperty(ref _menuItemIsEnabled, value);
}
}
[MvxFragment(typeof(MainViewModel), Resource.Id.content_frame, true)]
[Register(nameof(MyFragment))]
public class MyFragment : MvxFragment
{
private Toolbar Toolbar;
//menuitem whose enabled state should change with viewmodel property
private IMenuItem MyMenuItem;
public new MyViewModel ViewModel
{
get { return (MyViewModel)base.ViewModel; }
set { base.ViewModel = value; }
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
var view = base.OnCreateView(inflater, container, savedInstanceState);
//we'll need the Toolbar later when we set up the IsEnabled "binding"
Toolbar = view.FindViewById<Toolbar>(Resource.Id.toolbar);
return view;
}
public override void OnViewModelSet()
{
base.OnViewModelSet();
ViewModel.PropertyChanged += ViewModel_PropertyChanged;
}
public override void OnCreateOptionsMenu(IMenu menu, MenuInflater inflater)
{
base.OnCreateOptionsMenu(menu, inflater);
//create the menu based on a menu resource
inflater.Inflate(Resource.Menu.my_menu, menu);
//save a reference to the menu item so we can update it when the viewmodel changes
MyMenuItem = menu.FindItem(Resource.Id.my_menu_item);
//set the initial enabled state based on the viewmodel
MyMenuItem.SetEnabled(ViewModel.MenuItemIsEnabled);
}
private void ViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
//when ViewModel.MenuItemIsEnabled is updated, update the menuitem enabled state as well
if (e.PropertyName == nameof(ViewModel.MenuItemIsEnabled ))
BinContentsMenuItem?.SetEnabled(ViewModel.MenuItemIsEnabled);
}
}
以上是将 test.php 文件从copy('foo/test.php', 'bar/test.php');
传输到foo
的代码,因此必要时会覆盖任何文件。
我正在尝试实现上述目标,但有几个未定义的目录。我该怎么做?
总体
bar
的新文件。感谢任何帮助,谢谢!
答案 0 :(得分:0)
如你所写,你可以在参数和循环中传递一个数组,就像那样:
function fullCopy($oldDir = '', $newDir = []) {
foreach ($dir as $value){
if ( is_dir($oldDir && is_dir($newDir)) ) {
copy( $oldDir . '/test.php', $newDir . '/test.php');
}
}
}
fullCopy('foo', ['bar', 'bar2', 'bar3']);