我有这样的事情:
一张桌子,里面有更多学生的数据......内容是ID,姓名,姓氏和来自.....现在我在项目中添加了一个新类......它叫做BankAccount
学生可以拥有0个或更多帐户......
我将它们添加到学生的数据绑定过程中......
现在我想选择一个学生,并在同一页面上的列表框中显示他的(如果有的话)...到目前为止,我有这个代码:
与学生的桌子......
<table border="1" name="tableStud" arrow-selector>
<tbody>
<tr>
<td>ID</td>
<td>First Name</td>
<td>Last Name</td>
<td>From</td>
</tr>
<tr ng-repeat="student in result"
ng-class="{'selected':$index == selectedRow}"
ng-click="setSelected(student,$index)">
<td>{{ student.id }}</td>
<td>{{ student.firstname }}</td>
<td>{{ student.lastname }}</td>
<td>{{ student.mestorodjenja.ime }}</td>
</tr>
</tbody>
</table>
<select ng-model="student.accounts" multiple="multiple"
ng-options="account.name for account in student.accounts track by account.id"
>
</select>
在控制器中,我得到了这个:
$scope.setSelected = function(student, index) {
$scope.student = student;
$scope.selectedRow = index;
};
现在的问题是,我的列表框显示所选学生的帐户....但它们都是SELECTED,一旦我按下其中一个,其他人消失,而按下的那个仍然被选中。 ...
最重要的是,一旦我转到另一个学生,然后回来......列表框中所有丢失的帐户仍然丢失....而且旧的帐户也被选中......
最后我的问题是:
是否可以选择学生,并且他的帐户将在列表框中显示而不被选中....并且在我按下它们后不会消失...?
提前谢谢!答案 0 :(得分:1)
只需替换所选学生的变量即可。喜欢:
//java code
public class Location_Track1 extends Activity {
private static final String TAG = "Location_Track1";
private static final long INTERVAL = 1000 * 60 * 1; //1 minute
private static final long FASTEST_INTERVAL = 1000 * 60 * 1; // 1 minute
private static final float SMALLEST_DISPLACEMENT = 0.25F; //quarter of a meter
Button btnFusedLocation;
TextView tvLocation;
LocationRequest mLocationRequest;
GoogleApiClient mGoogleApiClient;
Location mCurrentLocation;
String mLastUpdateTime;
GoogleMap googleMap;
private ImageView mCurrentPointer;
private double longitude;
private double latitude;
// private ArrayList<LatLng> points; //added
private List<LatLng> points = new ArrayList<>();
Polyline line; //added
TextView tv_mobno, tv_latitude, tv_longitude, tv_time;
String getLatitude;
String getLongitude;
Button slocation;
JSONArray result = null;
ProgressDialog mProgressDialog;
ArrayList<HashMap<String, String>> arraylist;
static String CON = "CON";
JSONObject jsonobject;
JSONArray jsonarray;
private String url ="";
private static final String TAG_USER = "result";
// private static final String TAG_SNAME = "pseats";
private static final String TAG_LONG = "longitude";
private static final String TAG_LAT = "latitude";
private static final String TAG_ADDRESS = "paddress";
protected void createLocationRequest() {
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(INTERVAL);
mLocationRequest.setFastestInterval(FASTEST_INTERVAL);
mLocationRequest.setSmallestDisplacement(SMALLEST_DISPLACEMENT); //added
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.location_track);
Log.d(TAG, "onCreate ...............................");
tv_mobno=(TextView)findViewById(R.id.textView_mob);
tv_latitude=(TextView)findViewById(R.id.textView_latitude);
tv_longitude=(TextView)findViewById(R.id.textView_longitude);
tv_time=(TextView)findViewById(R.id.textView_time);
slocation=(Button)findViewById(R.id.button_slocation);
url = "http://example.in/gmap_track.php";
// points = new ArrayList<LatLng>();
googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
slocation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// new DownloadJSON().execute();
new JSONParse().execute();
}
});
}
private class JSONParse extends AsyncTask<String, String, JSONObject> {
private ProgressDialog pDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Location_Track1.this);
pDialog.setMessage("Getting Data ...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected JSONObject doInBackground(String... args) {
JSONParser jParser = new JSONParser();
// Getting JSON from URL
JSONObject json = jParser.getJSONFromUrl(url);
return json;
}
@Override
protected void onPostExecute(JSONObject json) {
pDialog.dismiss();
try {
// Getting JSON Array
result = json.getJSONArray(TAG_USER);
JSONObject c = result.getJSONObject(0);
// Storing JSON item in a Variable
String lat = c.getString(TAG_LAT);
String longt = c.getString(TAG_LONG);
//Set JSON Data in TextView
tv_latitude.setText(lat);
tv_longitude.setText(longt);
/* double lat = c.getDouble(TAG_LAT);
double longt = c.getDouble(TAG_LONG);
MarkerOptions marker = new MarkerOptions().position(new LatLng(lat, longt)).title("point");
googleMap.addMarker(marker);*/
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
HTML :
$scope.setSelected = function(student, index) {
$scope.selectedstudent = student;
$scope.selectedRow = index;
};