本篇文章给大家谈谈javascript–ng-options,对象设置为ng-model,以及js设置对象的key的知识点,同时本文还将给你拓展c#–JavaScript–如何在Javascript中
本篇文章给大家谈谈javascript – ng-options,对象设置为ng-model,以及js设置对象的key的知识点,同时本文还将给你拓展c# – JavaScript – 如何在Javascript中将值设置为Session、Calling Flex / Actionscript functions from Javascript、JavaScript Scoping and Hoisting 翻译_javascript技巧、javascript select options 排序(保持option 对象完整性)等相关知识,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:- javascript – ng-options,对象设置为ng-model(js设置对象的key)
- c# – JavaScript – 如何在Javascript中将值设置为Session
- Calling Flex / Actionscript functions from Javascript
- JavaScript Scoping and Hoisting 翻译_javascript技巧
- javascript select options 排序(保持option 对象完整性)
javascript – ng-options,对象设置为ng-model(js设置对象的key)
<divng-repeat="question in currentTemplate.questions"> <divng-show="editingQuestion[$index]"> <selectng-model="editingCurrentlySelectedAnswerOption[$index]" ng-options="answerOption as answerOption.back for answerOption in answerOptions"> </select> </div> </div>
我想知道如何设置select语句中显示的值.当页面加载时,它应该已经设置,因为我通过for循环来设置editingCurrentlySelectedAnswerOption的值,以便每个都被预先选择([$index]指的是ng-repeat的索引,这是在里面因为在ng-repeat中有多个选择,我需要在数组中每个ng-repeat一个点来跟踪每个单独的选择),但是它首先作为空白点出现.我使用了ng-init,一个按下按钮时调用的函数,它取消隐藏上面的div,以及页面加载时的函数.我在DOM和console.logs中使用了绑定来检查值.他们似乎都是正确的. ng-options中的answerOptions是:
var answerOptions = [ { front: "RadioButton",back: "Multi-Choice" } { front: "CheckBox",back: "Multi-Answer" } { front: "TextBox",back: "Free Text" } ];
当我打印editCurrentlySelectedAnswerOption [$index]时,它总是正确显示一个对象,就像上面的一个对象一样,但由于某种原因,它在加载时总是一个空白的select语句.有什么我不知道ng-options如何与对象一起工作?或者我做错了什么?
更新:
我这样设置editingCurrentlySelectedAnswerOption的值:
this.scope.editingCurrentlySelectedAnswerOption = []; for (var i in this.scope.currentTemplate.questions) { if (this.scope.currentTemplate.questions.hasOwnProperty(i)) { this.scope.editingCurrentlySelectedAnswerOption.push(this.scope.currentTemplate.questions[i].answerType); } }
我在this.scope.currentTemplate中增加问题的次数的原因是因为在html中ng-repeat重复了问题的数量.他们应该匹配.
这就是this.scope.currentTemplate.questions [0]的定义方式:
new Utilities.Question( "Question1",{ front: "TextBox",back: "Free Text" },["Yes","Maybe","No","I don't kNow"],[50.0,25.0,0.0,-25.0] )
这是Utilities.Question的定义:
export class Question { question: string; answerType: any; answerOptions: string[]; answerWeights: number[]; constructor(question?: string,answerType?: any,answerOptions?: string[],answerWeights?: number[]) { this.question = question; this.answerType = answerType; this.answerOptions = answerOptions; this.answerWeights = answerWeights; } }
解决方法
c# – JavaScript – 如何在Javascript中将值设置为Session
<%session["Test"] = "Welcome Mamu";%> var session_value='<%=Session["Test"]%>'; alert(session_value);
以上工作很好.请注意,我已分配静态值(欢迎Mamu).但对于Dynamatic,
var strTest=document.getElementById('DropDownList1').value; <%session["Test"] = "'+ strTest +'";%>
它在客户端工作正常.但是我的服务器端(Code Behind),Session [“Test”]值是’strTest’.
是否有任何其他方式为Session分配值?
解决方法@H_301_23@
无法通过javascript直接分配会话值.
我找到了其他方法.调用函数后面的代码并分配会话值.
Javascript功能:
function InitializeRequest(path)
{
// call server side method
PageMethods.SetDownloadpath(path);
}
[System.Web.Services.WebMethod]
public static string SetDownloadpath(string strpath)
{
Page objp = new Page();
objp.Session["strDwnPath"] = strpath;
return strpath;
}
必须启用页面方法设置为true
< asp:ScriptManager EnablePageMethods =“true”ID =“MainSM”runat =“server”ScriptMode =“Release”LoadScriptsBeforeUI =“true”>< / asp:ScriptManager>
我找到了其他方法.调用函数后面的代码并分配会话值.
Javascript功能:
function InitializeRequest(path) { // call server side method PageMethods.SetDownloadpath(path); } [System.Web.Services.WebMethod] public static string SetDownloadpath(string strpath) { Page objp = new Page(); objp.Session["strDwnPath"] = strpath; return strpath; }
必须启用页面方法设置为true
< asp:ScriptManager EnablePageMethods =“true”ID =“MainSM”runat =“server”ScriptMode =“Release”LoadScriptsBeforeUI =“true”>< / asp:ScriptManager>
Calling Flex / Actionscript functions from Javascript
Nowadays I am working with Flex projects,that runs on Lotus Notes platform,which consumes data from Lotus Notes backend. Since there is no remote services like BlazeDS to connect to Notes server,am Now greatly dependant on HTTPService and Javascript. Calling a javascript function from Flex is quite easy. Just use the ExternalInterface API. For those who don’t kNow the way,this is how it is getting called.
In AS3
if(ExternalInterface.available){
ExternalInterface.call(“openNotes”,parameter);
}
In Javascript
function openNotes(notesUrl){
window.open(notesUrl,”,‘width=1000,height=600′);
}
It is quite easy. But what if you need to call the reverse. ie,calling actionscript function from javascript. We can use the sameExternalInterface api for achieve this. There is a method calledaddCallback,available in ExternalInterface. addCallback method registers an ActionScript method as callable from the container. After a successful invocation of addCallBack()
,the registered function in the player can be called by JavaScript or ActiveX code in the container. The first parameter is the name by which the container can invoke the function and the second parameter is the function closure to invoke. Below is the step-by-step configuration:
Step 1 : Register the call back from actionscript. For eg,call the below method in the creationComplete or initialize event of the component.
private function createCallBack(event:Event):void{
ExternalInterface.addCallback(“updateNotes”,getNotes);
}private function getNotes():void{
//do whatever you want after getting the hold
}
Step 2 : Create logic in javascript to invoke the AS3 function.
//Javascript
function updateFlex(){
appName.updateNotes();
}
The appName is the name and id of the embedded swf object in the HTML. Like below :
…
That’s it. Now you can call the updateFlex javascript method from your HTML and it will invoke the AS3 callback function. Enjoy Coding guys. Flex Your Life. Cheers.
Reference:
http://deviltechie.wordpress.com/2012/05/08/calling-flex-actionscript-functions-from-javascript/
JavaScript Scoping and Hoisting 翻译_javascript技巧
你知道下面的JavaScript代码执行后会alert出什么值吗?
var foo = 1;
function bar() {
if (!foo) {
var foo = 10;
}
alert(foo);
}
bar();
如果答案是"10"令你感到惊讶的话,那么下面这个会让你更加困惑:
[/code]
var a = 1;
function b() {
a = 10;
return;
function a() {}
}
b();
alert(a);
[/code]
浏览器会alert“1”。那么,到底是怎么了?尽管这看起来有点奇怪、有点危险又有点令人困惑,但这事实上却是这门语言一个强力的具有表现力的特性。我不知道是不是有个标准来定义这种行为,但是我喜欢用”hoisting”来描述。这篇文章试着去解释这种机制,但是首先,让我们对JavaScript的scoping做一些必要的了解。
Scoping in JavaScript
对于JavaScript新手来说scoping是最令人困惑的部分之一。事实上,不仅仅是新手,我遇到或很多有经验的JavaScript程序员也不能完全理解scoping。JavaScript的scoping如此复杂的原因是它看上去非常像C系语言的成员。请看下面的C程序:
#include
int main() {
int x = 1;
printf("%d, ", x); // 1
if (1) {
int x = 2;
printf("%d, ", x); // 2
}
printf("%d\n", x); // 1
}