JavaScript初学者:为什么这不起作用?(JavaScript beginner: why does this not work?)
我的html页面没有响应我在JS中编写的这段代码,我是一个初学者,刚开始学习JS,有人可以告诉我为什么这不起作用?
/* this is a practice file that'll play with js nothing strange to look at here folks! */ var firstName = 'Steven'; var lastName = 'Curry'; var fullName = firstName + ' ' + lastName; function Hotel(HotelName){ this.HotelName = HotelName; this.numRooms = 20; this.numGuests; this.checkAvailability { if(numRooms != 20 ){ return true; } else{ return false; } } this.getHotelName = function(){ //can it work with this dot operator? return this.HotelName; } } var HiltonHotel = new Hotel('Hilton'); var hName = document.getElementById('hotelName'); hName.textContent = getHotelName(); var el = document.getElementById('name'); el.textContent = fullName;
<!DOCTYPE html> <html> <body> <div id = 'greeting'> Hello <span id="name">friend</span>! <h1>Welcome To the <span id = 'hotelName'>Hyatt</span> </div> <script src = "https://stacksnippets.net/js"> </script> </body> </html
我很确定它的排序和我的语法我需要继续工作,非常感谢任何建议,谢谢!
My html page is not responding to this code I wrote in JS, i'm a total beginner, and just started learning JS, can somebody tell me why this doesn't work?
/* this is a practice file that'll play with js nothing strange to look at here folks! */ var firstName = 'Steven'; var lastName = 'Curry'; var fullName = firstName + ' ' + lastName; function Hotel(HotelName){ this.HotelName = HotelName; this.numRooms = 20; this.numGuests; this.checkAvailability { if(numRooms != 20 ){ return true; } else{ return false; } } this.getHotelName = function(){ //can it work with this dot operator? return this.HotelName; } } var HiltonHotel = new Hotel('Hilton'); var hName = document.getElementById('hotelName'); hName.textContent = getHotelName(); var el = document.getElementById('name'); el.textContent = fullName;
<!DOCTYPE html> <html> <body> <div id = 'greeting'> Hello <span id="name">friend</span>! <h1>Welcome To the <span id = 'hotelName'>Hyatt</span> </div> <script src = "https://stacksnippets.net/js"> </script> </body> </html
I'm pretty sure it's ordering and my syntax i need to work on, any advice is greatly appreciated thank you!
原文:https://stackoverflow.com/questions/44790585
最满意答案
您应该为
CartViewModel
所有CartItemViewModel
实例处理PropertyChanged
事件。 您收到PropertyChangedEventArgs
,其中有一个名为PropertyName
的成员。 当它的值为“Raispropertychanged(TotalValue)
”时,您可以调用Raispropertychanged(TotalValue)
。 代码完全添加到CartViewModel
。You should handle the
PropertyChanged
event for all the instances ofCartItemViewModel
inside theCartViewModel
. You receivePropertyChangedEventArgs
which has a member calledPropertyName
. When its value is "SubTotal" then you can callRaispropertychanged(TotalValue)
. The code is completely added toCartViewModel
.
相关问答
更多-
MvvmCross命令模式(MvvmCross Command Pattern)[2021-07-18]
第一个版本只是减少了创建的对象数量,因为无论访问命令属性多少次,都只存在一个实例。 在大多数情况下,这可能没有那么大的差别。 大多数人使用代码片段来生成代码,因此生成正确的代码不是任何额外的输入。 The first version simply reduces the number of objects created, since only one instance would exist no matter how many times the command property is accessed ... -
Mvvmcross片段(Mvvmcross fragments)[2022-05-12]
我发现问题=>显然MvxCachingFragmentCompatActivity由于某种原因不喜欢MvxCachingFragmentCompatActivity 。 第一个样品(工作) 在第一个示例中,我直接在从MvxCachingFragmentCompatActivity扩展的MainViewModel上执行RegisterAppStart<> 。 这是完美的 一些代码示例( 完整代码请参阅链接 ) public class App : MvvmCross.Core.ViewModels.MvxAp ... -
MvvmCross绑定的变化(Changes in MvvmCross bindings)[2022-07-13]
正如我们在OP的评论中所做的那样,交换机的事件被联系起来了。 因此,绑定没有做任何事情。 解决此问题的最简单方法是将以下代码添加到LinkerPleaseInclude.cs文件中,MvvmCross在Startup NuGet中提供该文件,并通过可用于Visual Studio和Xamarin Studio的模板: public void Include(UISwitch sw) { sw.On = !sw.On; sw.ValueChanged += (sender, args) = ... -
可以在MvvmCross中执行(CanExecute in MvvmCross)[2021-10-29]
更新Quantity属性时忘记调用RaiseCanExecuteChanged 。 另外,您不需要设置始终返回true的CanExecute : public class CartItemViewModel : MvxNotifyPropertyChanged { private int quantity = 0; public CartItemViewModel() { IncreaseCommand = new MvxCommand(Ex ... -
您应该为CartViewModel所有CartItemViewModel实例处理PropertyChanged事件。 您收到PropertyChangedEventArgs ,其中有一个名为PropertyName的成员。 当它的值为“ Raispropertychanged(TotalValue) ”时,您可以调用Raispropertychanged(TotalValue) 。 代码完全添加到CartViewModel 。 You should handle the PropertyChanged ev ...
-
Mvx.MvxBindableListView是一个旧名称,在MvvmCross v.3中,这个控件叫做Mvx.MvxListView https://github.com/MvvmCross/MvvmCross/blob/v3.1/Cirrious/Cirrious.MvvmCross.Binding.Droid/Views/MvxListView.cs Mvx.MvxBindableListView is an old name, in MvvmCross v.3 this control is cal ...
-
从tracem看,它看起来像是一个直截了当的错误,可能是在解决另一个问题时出现在某处的回归。 你最好的选择是在GitHub上为此打开一个问题 - https://github.com/slodge/MvvmCross/issues/new ? 或者你可以将源代码分解并将其修复到你的分支中。 在此期间,也许尝试使用MvxListView? 或者创建一个新的可绑定ViewGroup? From the tracem it looks like a straight-forward bug, probably a ...
-
SideMenu for mvvmCross(SideMenu for mvvmCross)[2022-06-01]
该跟踪由MvxSidebarViewController中的MvxSidebarViewController代码触发。 protected virtual void SetupSideMenu() { var leftSideMenu = ResolveSideMenu(MvxPanelEnum.Left); var rightSideMenu = ResolveSideMenu(MvxPanelEnum.Right); if (leftSi ... -
我相信LegacyBar已经与MvvmCross一起使用 - 所以这肯定是你的选择。 或者,另一个可用选项是为Sherlock中的活动和/或片段添加数据绑定支持。 对于活动,MvvmCross使用几个小的代码层将活动调整为数据绑定: 生活场所 数据绑定上下文 这个代码在MVVMCross for android中描述- 如何在代码中进行绑定? 如果您按照该问题中“附加”部分中的两个步骤操作,那么应该可以创建MvxSherlockActivity 对于片段,这里没有详细的现有答案,但这个过程基本上是相同的两个 ...
-
MVVMCROSS ShowViewModel-Navigation Inherited Class(MVVMCROSS ShowViewModel-Navigation Inherited Class)[2022-04-07]
您可以调整任何ViewController基类,以允许通过从中继承来提供MvvmCross数据绑定扩展。 例如,看看UIViewController本身如何在2层继承中进行调整: https://github.com/MvvmCross/MvvmCross/blob/v3.1/CrossCore/Cirrious.CrossCore.Touch/Views/MvxEventSourceViewController.cs https://github.com/MvvmCross/MvvmCross/blob/ ...