【发布时间】:2016-05-11 09:03:39
【问题描述】:
我想在我的编辑视图中访问一些属性来更改一些值。
我尝试使用<%=course.scoreAlgo=> 之类的方式进行访问,但这不起作用。
我似乎无法访问模型中script 标记内的任何属性。非常感谢任何和所有帮助我如何访问它!
课程模型:
module.exports = {
attributes: {
code:{
type: "string"
},
name:{
type: "string"
},
recitations:{
type: 'array',
defaultsTo: 0
},
finishedAssignments:{
type: "array"
},
recitationScore:{
type: 'integer',
defaultsTo: 0
},
recitationGroup:{
type: "string",
defaultsTo: "none"
},
shown:{
type: "string",
defaultsTo: "no"
},
scoreAlgo:{
type:"array"
},
takes:{
model: 'student'
}
}
};
这就是我试图制作的代码的样子:
<form action="/course/update/<%= course.id %>" method="POST">
<h2>Edit course</h2>
<input value="<%= course.code%>" type="text" name="code"><br/>
<input value="<%= course.name%>" type="text" name="name"><br/>
<input value="<%= course.shown %>" type="text" name="shown"><br/>
<input value="<%= course.recitationScore%>" type="text" name="recitationScore"><br/>
<p>Score algo, specify by saying how many have to be completed for each "subgroup".
If two from a, two from b and one from c means full score, put "2,2,1"</p>
<input value="<%=course.scoreAlgo%>" type="text" name="scoreAlgo">
<input type="button" value="Calculate recitationScore" onclick="calcScore()">
<script>
function calcScore(){
var stringArray = course.finishedAssignments;
var scoreAlgo = course.scoreAlgo;
for(var i=0; i < stringArray.length; i++){
var str = stringArray[i];
var sStr = str.split(",");
for(var j=0; j < sStr.length; j++){
var count = scoreAlgo[i]
var s = sStr[i];
var sS = s.split((i+1).toString);
if(sS.length >= count){
var score = sS.length*33;
course.recitationScore = course.recitationScore + score;
console.log(score);
}
}
}
}
</script>
<input type="submit" value="Edit course"/>
</form>
【问题讨论】:
标签: javascript node.js model sails.js